| 1 |
@Part(10, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2019/06/11 04:31:37 $} |
| 4 |
@LabeledSection{Program Structure and Compilation Issues} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/10.mss,v $} |
| 7 |
@Comment{$Revision: 1.113 $} |
| 8 |
@Comment{Corrigendum changes added, 2000/04/24, RLB} |
| 9 |
|
| 10 |
@begin{Intro} |
| 11 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 12 |
@redundant[The overall structure of programs and the facilities for separate |
| 13 |
compilation are described in this @Chg{Version=[3],New=[clause],Old=[section]}. |
| 14 |
A @i(program) is a set of @i(partitions), each of which |
| 15 |
may execute in a separate address space, possibly on a separate |
| 16 |
computer. |
| 17 |
@ToGlossary{Term=<Program>, |
| 18 |
Text=<A @i(program) is a set of @i(partitions), each of which |
| 19 |
may execute in a separate address space, possibly on a separate |
| 20 |
computer. |
| 21 |
A partition consists of a set of library units.>} |
| 22 |
@ToGlossary{Term=<Partition>, |
| 23 |
Text=<A @i(partition) is a part of a program. |
| 24 |
Each partition consists of a set of library units. |
| 25 |
Each partition may run in a separate address space, |
| 26 |
possibly on a separate computer. |
| 27 |
A program may contain just one partition. |
| 28 |
A distributed program typically contains multiple partitions, |
| 29 |
which can execute concurrently.>} |
| 30 |
|
| 31 |
@Defn2{Term=[library unit],Sec=(informal introduction)} |
| 32 |
@Defn2{Term=[library_item],Sec=(informal introduction)} |
| 33 |
@Defn2{Term=[library],Sec=(informal introduction)} |
| 34 |
As explained below, |
| 35 |
a partition is constructed from @i{library units}. |
| 36 |
Syntactically, the declaration of a library unit is a @nt{library_item}, |
| 37 |
as is the body of a library unit. |
| 38 |
An implementation may support a concept of a @i{program library} |
| 39 |
(or simply, a @lquotes@;library@rquotes@;), |
| 40 |
which contains @nt{library_item}s |
| 41 |
and their subunits. |
| 42 |
@IndexSee{Term=[program library],See=(library)} |
| 43 |
Library units may be organized into a hierarchy of |
| 44 |
children, grandchildren, and so on.] |
| 45 |
|
| 46 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 47 |
This @Chg{Version=[3],New=[clause],Old=[section]} has two |
| 48 |
@Chg{Version=[3],New=[subclauses],Old=[clauses]}: |
| 49 |
@RefSec{Separate Compilation} |
| 50 |
discusses compile-time issues related to separate compilation. |
| 51 |
@RefSec{Program Execution} |
| 52 |
discusses issues related to what is traditionally known as @lquotes@;link time@rquotes@; |
| 53 |
and @lquotes@;run time@rquotes@; @em building and executing partitions. |
| 54 |
|
| 55 |
@end{Intro} |
| 56 |
|
| 57 |
@begin{MetaRules} |
| 58 |
@Defn{avoid overspecifying environmental issues} |
| 59 |
We should avoid specifying details that are outside the domain of the |
| 60 |
language itself. |
| 61 |
The standard is intended (at least in part) |
| 62 |
to promote portability of Ada programs at the source level. |
| 63 |
It is not intended to standardize extra-language issues such as how one |
| 64 |
invokes the compiler (or other tools), |
| 65 |
how one's source is represented and organized, |
| 66 |
version management, the format of error messages, etc. |
| 67 |
|
| 68 |
@Defn{safe separate compilation} |
| 69 |
@Defn2{Term=[separate compilation], Sec=(safe)} |
| 70 |
The rules of the language should be enforced |
| 71 |
even in the presence of separate compilation. |
| 72 |
Using separate compilation should not make a |
| 73 |
program less safe. |
| 74 |
|
| 75 |
@Defn{legality determinable via semantic dependences} |
| 76 |
It should be possible to determine the legality of a |
| 77 |
compilation unit by looking only at the compilation unit itself |
| 78 |
and the compilation units upon which it depends semantically. |
| 79 |
As an example, it should be possible to analyze the legality of |
| 80 |
two compilation units in parallel if they do not depend semantically |
| 81 |
upon each other. |
| 82 |
|
| 83 |
On the other hand, it may be necessary to look outside that set in |
| 84 |
order to generate code @em this is generally true for |
| 85 |
generic instantiation and inlining, for example. |
| 86 |
Also on the other hand, |
| 87 |
it is generally necessary to look outside that set in |
| 88 |
order to check @LinkTimeName@;s. |
| 89 |
|
| 90 |
See also the @lquotes@;generic contract model@rquotes@; @MetaRulesName of |
| 91 |
@RefSec{Generic Instantiation}. |
| 92 |
@end{MetaRules} |
| 93 |
|
| 94 |
@begin{DiffWord83} |
| 95 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 96 |
The @Chg{Version=[3],New=[clause],Old=[section]} organization mentioned above is |
| 97 |
different from that of RM83. @end{DiffWord83} |
| 98 |
|
| 99 |
@LabeledClause{Separate Compilation} |
| 100 |
|
| 101 |
@begin{Intro} |
| 102 |
@redundant[@Defn{separate compilation} |
| 103 |
@Defn2{Term=[compilation], Sec=(separate)} |
| 104 |
@ToGlossaryAlso{Term=<Program unit>, |
| 105 |
Text=<A @i(program unit) is either a package, a task unit, |
| 106 |
a protected unit, a protected entry, a generic unit, |
| 107 |
or an explicitly declared subprogram other than an enumeration |
| 108 |
literal. |
| 109 |
Certain kinds of program units can be separately compiled. |
| 110 |
Alternatively, they can appear physically nested within |
| 111 |
other program units.>} |
| 112 |
|
| 113 |
@ToGlossaryAlso{Term=<Compilation unit>, |
| 114 |
Text=<The text of a program can be submitted to the compiler in one or |
| 115 |
more @nt(compilation)s. |
| 116 |
Each @nt(compilation) is a succession of @nt(compilation_unit)s. |
| 117 |
A @nt(compilation_unit) contains either |
| 118 |
the declaration, the body, or a renaming of a program unit.>}] |
| 119 |
The representation for a @nt<compilation> is implementation-defined. |
| 120 |
@ImplDef{The representation for a @nt{compilation}.} |
| 121 |
@begin{Ramification} |
| 122 |
Some implementations might choose to make a |
| 123 |
@nt{compilation} be a source (text) file. |
| 124 |
Others might allow multiple source files to be automatically |
| 125 |
concatenated to form a single @nt{compilation}. |
| 126 |
Others still may represent the source in a nontextual form such as a parse |
| 127 |
tree. |
| 128 |
Note that the RM95 does not even define the concept of a |
| 129 |
source file. |
| 130 |
|
| 131 |
Note that a protected subprogram is a subprogram, |
| 132 |
and therefore a program unit. |
| 133 |
An instance of a generic unit is a program unit. |
| 134 |
|
| 135 |
A protected entry is a program unit, |
| 136 |
but protected entries cannot be separately compiled. |
| 137 |
@end{Ramification} |
| 138 |
|
| 139 |
@ToGlossaryAlso{Term=<Library unit>, |
| 140 |
Text=<A library unit is a separately compiled |
| 141 |
program unit, |
| 142 |
and is always a package, subprogram, or generic unit. |
| 143 |
Library units may have other (logically nested) library units as children, |
| 144 |
and may have other program units physically nested within them. |
| 145 |
@Defn(subsystem) |
| 146 |
A root library unit, together with its children and grandchildren |
| 147 |
and so on, form a @i(subsystem).>} |
| 148 |
|
| 149 |
@end{Intro} |
| 150 |
|
| 151 |
@begin{ImplPerm} |
| 152 |
An implementation may impose implementation-defined restrictions |
| 153 |
on @nt{compilation}s that contain multiple @nt<compilation_unit>s. |
| 154 |
@ImplDef{Any restrictions on @nt<compilation>s that contain |
| 155 |
multiple @nt<compilation_unit>s.} |
| 156 |
@begin{Discussion} |
| 157 |
For example, an implementation might disallow a @nt{compilation} that |
| 158 |
contains two versions of the same compilation unit, or that |
| 159 |
contains the declarations for library packages P1 and P2, |
| 160 |
where P1 precedes P2 in the @nt<compilation> but P1 has a |
| 161 |
@nt<with_clause> that mentions P2. |
| 162 |
@end{Discussion} |
| 163 |
@end{ImplPerm} |
| 164 |
|
| 165 |
@begin{DiffWord83} |
| 166 |
The interactions between language issues and environmental issues |
| 167 |
are left open in Ada 95. The environment concept is new. |
| 168 |
In Ada 83, the concept of the program library, for example, |
| 169 |
appeared to be quite concrete, |
| 170 |
although the rules had no force, |
| 171 |
since implementations could get around them simply by defining various |
| 172 |
mappings from the concept of an Ada program library to whatever data |
| 173 |
structures were actually stored in support of separate compilation. |
| 174 |
Indeed, implementations were encouraged to do so. |
| 175 |
|
| 176 |
In RM83, it was unclear which was the official definition of |
| 177 |
@lquotes@;program unit.@rquotes@; |
| 178 |
Definitions appeared in RM83-5, 6, 7, and 9, but not 12. |
| 179 |
Placing it here seems logical, |
| 180 |
since a program unit is sort of a potential compilation unit. |
| 181 |
@end{DiffWord83} |
| 182 |
|
| 183 |
@LabeledSubClause{Compilation Units - Library Units} |
| 184 |
|
| 185 |
@begin{Intro} |
| 186 |
@redundant[A @nt{library_item} is a compilation unit that is the declaration, body, |
| 187 |
or renaming of a library unit. |
| 188 |
Each library unit (except Standard) has a @i{parent unit}, |
| 189 |
which is a library package or generic library package.] |
| 190 |
@Defn2{Term=[child], Sec=(of a library unit)} |
| 191 |
A library unit is a @i{child} of its parent unit. |
| 192 |
The @i{root} library units are the children of |
| 193 |
the predefined library package Standard. |
| 194 |
@begin{Ramification} |
| 195 |
Standard is a library unit. |
| 196 |
@end{Ramification} |
| 197 |
@end{Intro} |
| 198 |
|
| 199 |
@begin{Syntax} |
| 200 |
@Syn{lhs=<compilation>,rhs="{@Syn2{compilation_unit}}"} |
| 201 |
|
| 202 |
|
| 203 |
@Syn{lhs=<compilation_unit>,rhs=" |
| 204 |
@Syn2{context_clause} @Syn2{library_item} |
| 205 |
| @Syn2{context_clause} @Syn2{subunit}"} |
| 206 |
|
| 207 |
|
| 208 |
@Syn{lhs=<library_item>,rhs="[@key{private}] @Syn2{library_unit_declaration} |
| 209 |
| @Syn2{library_unit_body} |
| 210 |
| [@key{private}] @Syn2{library_unit_renaming_declaration}"} |
| 211 |
|
| 212 |
|
| 213 |
@Syn{tabs=[P25], lhs=<library_unit_declaration>,rhs=" |
| 214 |
@Syn2{subprogram_declaration}@\| @Syn2{package_declaration} |
| 215 |
| @Syn2{generic_declaration}@\| @Syn2{generic_instantiation}"} |
| 216 |
|
| 217 |
|
| 218 |
@Syn{lhs=<library_unit_renaming_declaration>,rhs=" |
| 219 |
@Syn2{package_renaming_declaration} |
| 220 |
| @Syn2{generic_renaming_declaration} |
| 221 |
| @Syn2{subprogram_renaming_declaration}"} |
| 222 |
|
| 223 |
|
| 224 |
@Syn{lhs=<library_unit_body>,rhs="@Syn2{subprogram_body} | @Syn2{package_body}"} |
| 225 |
|
| 226 |
|
| 227 |
@Syn{lhs=<parent_unit_name>,rhs="@Syn2{name}"} |
| 228 |
|
| 229 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]} |
| 230 |
@ChgAdded{Version=[2],Text=[An @nt{overriding_indicator} is not allowed in a |
| 231 |
@nt{subprogram_declaration}, @nt{generic_instantiation}, or |
| 232 |
@nt{subprogram_renaming_declaration} that declares a library unit.]} |
| 233 |
|
| 234 |
@begin{Reason} |
| 235 |
@ChgRef{Version=[2],Kind=[Added]} |
| 236 |
@ChgAdded{Version=[2],Text=[All of the listed items syntactically include |
| 237 |
@nt{overriding_indicator}, but a library unit can never override anything. |
| 238 |
A majority of the ARG thought that allowing @key{not overriding} in that |
| 239 |
case would be confusing instead of helpful.]} |
| 240 |
@end{Reason} |
| 241 |
@end{Syntax} |
| 242 |
|
| 243 |
@begin{Intro} |
| 244 |
@Defn{library unit} |
| 245 |
@PDefn{library}@Comment{There is a different definition of library in 10.1.4.} |
| 246 |
@Seealso{Primary=[library],Other=[library level]} |
| 247 |
@Seealso{Primary=[library],Other=[library unit]} |
| 248 |
@Seealso{Primary=[library],Other=[library_item]} |
| 249 |
A @i{library unit} is a program unit that is declared by a |
| 250 |
@nt{library_item}. |
| 251 |
When a program unit is a library unit, |
| 252 |
the prefix @lquotes@;library@rquotes@; is used to refer to it (or @lquotes@;generic library@rquotes@; |
| 253 |
if generic), |
| 254 |
as well as to its declaration and body, |
| 255 |
as in @lquotes@;library procedure@rquotes@;, @lquotes@;library @nt{package_body}@rquotes@;, or |
| 256 |
@lquotes@;generic library package@rquotes@;. |
| 257 |
@Defn{compilation unit} |
| 258 |
The term @i{compilation unit} is used to refer to |
| 259 |
a @nt{compilation_unit}. |
| 260 |
When the meaning is clear from context, |
| 261 |
the term is also used to refer to the @nt{library_item} |
| 262 |
of a @nt{compilation_unit} |
| 263 |
or to the @nt{proper_body} of a @nt{subunit} |
| 264 |
@Redundant[(that is, the @nt{compilation_unit} without the |
| 265 |
@nt{context_clause} and the @key[separate] (@nt{parent_unit_name}))]. |
| 266 |
@begin{Discussion} |
| 267 |
@leading@keepnext@;In this example: |
| 268 |
@begin{Example} |
| 269 |
@key[with] Ada.Text_IO; |
| 270 |
@key[package] P @key[is] |
| 271 |
... |
| 272 |
@key[end] P; |
| 273 |
@end{Example} |
| 274 |
|
| 275 |
the term @lquotes@;compilation unit@rquotes@; can refer to this text: @lquotes@;@key[with] Ada.Text_IO; |
| 276 |
@key[package] P @key[is] ... @key[end] P;@rquotes@; or to this text: |
| 277 |
@lquotes@;@key[package] P @key[is] ... @key[end] P;@rquotes@;. We use this shorthand |
| 278 |
because it corresponds to common usage. |
| 279 |
|
| 280 |
We like to use the word @lquotes@;unit@rquotes@; for declaration-plus-body things, |
| 281 |
and @lquotes@;item@rquotes@; for declaration or body separately (as in |
| 282 |
@nt{declarative_item}). |
| 283 |
The terms @lquotes@;@nt{compilation_unit},@rquotes@; @lquotes@;compilation unit,@rquotes@; |
| 284 |
and @lquotes@;@nt{subunit}@rquotes@; are exceptions to this rule. |
| 285 |
We considered changing @lquotes@;@nt{compilation_unit},@rquotes@; @lquotes@;compilation unit@rquotes@; |
| 286 |
to @lquotes@;@ntf{compilation_item},@rquotes@; @lquotes@;compilation item,@rquotes@; |
| 287 |
respectively, but we decided not to. |
| 288 |
@end{Discussion} |
| 289 |
|
| 290 |
@Defn2{Term=[parent declaration], Sec=(of a @nt{library_item})} |
| 291 |
@Defn2{Term=[parent declaration], Sec=(of a library unit)} |
| 292 |
The @i{parent declaration} of a @nt{library_item} |
| 293 |
(and of the library unit) is the declaration denoted |
| 294 |
by the @nt{parent_@!unit_name}, if any, of the |
| 295 |
@nt{defining_@!program_@!unit_name} of the @nt<library_item>. |
| 296 |
@Defn{root library unit} |
| 297 |
If there is no @nt{parent_@!unit_name}, |
| 298 |
the parent declaration is the declaration of Standard, |
| 299 |
the @nt{library_item} is a @i{root} @nt{library_item}, and |
| 300 |
the library unit (renaming) is a @i{root} library |
| 301 |
unit (renaming). |
| 302 |
The declaration and body of Standard itself have no parent declaration. |
| 303 |
@Defn2{Term=[parent unit], Sec=(of a library unit)} |
| 304 |
The @i{parent unit} of a @nt{library_item} or library unit is the |
| 305 |
library unit declared by its parent declaration. |
| 306 |
@begin{Discussion} |
| 307 |
The declaration and body of Standard are presumed to exist from |
| 308 |
the beginning of time, as it were. |
| 309 |
There is no way to actually write them, |
| 310 |
since there is no syntactic way to indicate lack of a parent. |
| 311 |
An attempt to compile a package Standard would result in |
| 312 |
Standard.Standard. |
| 313 |
@end{Discussion} |
| 314 |
@begin{Reason} |
| 315 |
Library units (other than Standard) |
| 316 |
have @lquotes@;parent declarations@rquotes@; and @lquotes@;parent units@rquotes@;. |
| 317 |
Subunits have @lquotes@;parent bodies@rquotes@;. |
| 318 |
We didn't bother to define the other possibilities: |
| 319 |
parent body of a library unit, |
| 320 |
parent declaration of a subunit, |
| 321 |
parent unit of a subunit. |
| 322 |
These are not needed, |
| 323 |
and might get in the way of a correct definition of @lquotes@;child.@rquotes@; |
| 324 |
@end{Reason} |
| 325 |
|
| 326 |
@Redundant[The children of a library unit occur immediately |
| 327 |
within the declarative region of the declaration of the library unit.] |
| 328 |
@Defn2{Term=[ancestor], Sec=(of a library unit)} |
| 329 |
The @i{ancestors} of a library unit are itself, its parent, |
| 330 |
its parent's parent, and so on. |
| 331 |
@Redundant[(Standard is an ancestor of every library unit.)] |
| 332 |
@Defn{descendant} |
| 333 |
The @i{descendant} relation is the inverse of the ancestor relation. |
| 334 |
@begin{Reason} |
| 335 |
These definitions are worded carefully to avoid defining subunits as |
| 336 |
children. Only library units can be children. |
| 337 |
|
| 338 |
We use the unadorned term @lquotes@;ancestors@rquotes@; here to concisely define both |
| 339 |
@lquotes@;ancestor unit@rquotes@; and @lquotes@;ancestor declaration.@rquotes@; |
| 340 |
@end{Reason} |
| 341 |
|
| 342 |
@Defn{public library unit} |
| 343 |
@Defn{public declaration of a library unit} |
| 344 |
@Defn{private library unit} |
| 345 |
@Defn{private declaration of a library unit} |
| 346 |
A @nt<library_unit_declaration> |
| 347 |
or a @nt<library_@!unit_@!renaming_@!declaration> is @i{private} |
| 348 |
if the declaration is immediately preceded |
| 349 |
by the reserved word @key{private}; |
| 350 |
it is otherwise @i{public}. A library unit is private or public |
| 351 |
according to its declaration. |
| 352 |
@Defn2{Term=[public descendant], Sec=(of a library unit)} |
| 353 |
The @i{public descendants} of a library unit are the library unit |
| 354 |
itself, and the public descendants of its public children. |
| 355 |
@Defn2{Term=[private descendant], Sec=(of a library unit)} |
| 356 |
Its other descendants are @i{private descendants}. |
| 357 |
@begin{Discussion} |
| 358 |
The first concept defined here is that a @nt<library_item> is either public |
| 359 |
or private (not in relation to anything else @em it's just a property of |
| 360 |
the library unit). |
| 361 |
The second concept is that a @nt<library_item> |
| 362 |
is a public descendant or |
| 363 |
private descendant @i{of a given ancestor}. |
| 364 |
A given @nt<library_item> can be a |
| 365 |
public descendant of one of its ancestors, |
| 366 |
but a private descendant of some other ancestor. |
| 367 |
|
| 368 |
A subprogram declared by a @nt{subprogram_body} |
| 369 |
(as opposed to a @nt{subprogram_declaration}) |
| 370 |
is always public, |
| 371 |
since the syntax rules disallow the reserved word @key[private] |
| 372 |
on a body. |
| 373 |
|
| 374 |
Note that a private library unit is a @i{public} |
| 375 |
descendant of itself, |
| 376 |
but a @i{private} descendant of its parent. |
| 377 |
This is because it is visible outside itself @em its |
| 378 |
privateness means that it is not visible outside its |
| 379 |
parent. |
| 380 |
|
| 381 |
Private children of Standard are legal, and follow the normal rules. |
| 382 |
It is intended that implementations might have some method for taking an |
| 383 |
existing environment, and treating it as a package to be @lquotes@;imported@rquotes@; into |
| 384 |
another environment, treating children of Standard in the imported environment |
| 385 |
as children of the imported package. |
| 386 |
@end{Discussion} |
| 387 |
@begin{Ramification} |
| 388 |
@leading@;Suppose we have a public library unit A, |
| 389 |
a private library unit A.B, and a public library unit A.B.C. |
| 390 |
A.B.C is a public descendant of itself and of A.B, |
| 391 |
but a private descendant of A; |
| 392 |
since A.B is private to A, we don't allow A.B.C to escape outside A |
| 393 |
either. |
| 394 |
This is similar to the situation that would occur with physical |
| 395 |
nesting, like this: |
| 396 |
@begin{Example} |
| 397 |
@key[package] A @key[is] |
| 398 |
@key[private] |
| 399 |
@key[package] B @key[is] |
| 400 |
@key[package] C @key[is] |
| 401 |
@key[end] C; |
| 402 |
@key[private] |
| 403 |
@key[end] B; |
| 404 |
@key[end] A; |
| 405 |
@end{Example} |
| 406 |
|
| 407 |
Here, A.B.C is visible outside itself and outside A.B, but not outside A. |
| 408 |
(Note that this example is intended to illustrate the visibility |
| 409 |
of program units from the outside; |
| 410 |
the visibility within child units is not quite identical to that of |
| 411 |
physically nested units, |
| 412 |
since child units are nested after their parent's declaration.) |
| 413 |
@end{Ramification} |
| 414 |
|
| 415 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 416 |
@ChgAdded{Version=[2],Text=[For each library @nt{package_declaration} in the |
| 417 |
environment, there is an implicit declaration of a |
| 418 |
@i{limited view} of that library package.@Defn{limited view} The |
| 419 |
limited view of a package contains:]} |
| 420 |
|
| 421 |
@begin(Itemize) |
| 422 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 423 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0129-1],ARef=[AI05-0262-1]} |
| 424 |
@ChgAdded{Version=[2],Text=[For each@Chg{Version=[3],New=[],Old=[ nested]} |
| 425 |
@nt{package_declaration}@Chg{Version=[3],New=[ occurring immediately within |
| 426 |
the visible part],Old=[]}, a declaration of the limited view of that package, |
| 427 |
with the same @nt{defining_program_unit_name}.]} |
| 428 |
|
| 429 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00326-01]} |
| 430 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0108-1],ARef=[AI05-0129-1],ARef=[AI05-0262-1]} |
| 431 |
@ChgAdded{Version=[2],Text=[For each @nt{type_declaration} |
| 432 |
@Chg{Version=[3],New=[occurring immediately within],Old=[in]} the visible |
| 433 |
part@Chg{Version=[3],New=[ that is not an |
| 434 |
@nt{incomplete_type_declaration}],Old=[]}, an incomplete view |
| 435 |
of the type@Chg{Version=[3],New=[ with no @nt{discriminant_part}],Old=[]}; |
| 436 |
if the @nt{type_declaration} is tagged, then the view is a |
| 437 |
tagged incomplete view.]} |
| 438 |
@begin{Reason} |
| 439 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0108-1]} |
| 440 |
@ChgAdded{Version=[3],Text=[The incomplete view of a type does not have |
| 441 |
a discriminant_part even if the @nt{type_declaration} does have |
| 442 |
one. This is necessary because semantic analysis (and the associated |
| 443 |
dependence on @nt{with_clause}s) would be necessary |
| 444 |
to determine the types of the discriminants.]} |
| 445 |
|
| 446 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0129-1]} |
| 447 |
@ChgAdded{Version=[3],Text=[No incomplete views of incomplete types are |
| 448 |
included in the limited view. The rules of |
| 449 |
@RefSecNum{Incomplete Type Declarations} ensure that the completion of any |
| 450 |
visible incomplete type is declared in the same visible part, so such |
| 451 |
an incomplete view would simply be redundant.]} |
| 452 |
@end{Reason} |
| 453 |
@end(Itemize) |
| 454 |
|
| 455 |
@begin(Discussion) |
| 456 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 457 |
@ChgAdded{Version=[2],Text=[The implementation model of a limited view is that it |
| 458 |
can be determined solely from the syntax of the source of the unit, without |
| 459 |
any semantic analysis. That allows it to be created without the semantic |
| 460 |
dependences of a full unit, which is necessary for it to break mutual |
| 461 |
dependences of units.]} |
| 462 |
@end(Discussion) |
| 463 |
|
| 464 |
@begin(Ramification) |
| 465 |
@ChgRef{Version=[2],Kind=[Added]} |
| 466 |
@ChgAdded{Version=[2],Text=[The limited view does not include package instances and |
| 467 |
their contents. Semantic analysis of a unit (and dependence on its |
| 468 |
@nt{with_clause}s) would be needed to determine the contents of an instance.]} |
| 469 |
@end(Ramification) |
| 470 |
|
| 471 |
@ChgRef{Version=[2],Kind=[Added]} |
| 472 |
@ChgAdded{Version=[2],Text=[The limited view of a library @nt{package_declaration} is private if that |
| 473 |
library @nt{package_declaration} is immediately preceded by the reserved word |
| 474 |
@key{private}.]} |
| 475 |
|
| 476 |
@ChgRef{Version=[2],Kind=[Added]} |
| 477 |
@ChgAdded{Version=[2],Text=[@Redundant[There is no syntax for declaring limited |
| 478 |
views of packages, because they are always implicit.] The implicit declaration |
| 479 |
of a limited view of a library package @Redundant[is not the declaration of a |
| 480 |
library unit (the library @nt{package_declaration} is); nonetheless, it] is a |
| 481 |
@nt{library_item}. The implicit declaration of the limited view of a library |
| 482 |
package forms an (implicit) compilation unit whose @nt{context_clause} is |
| 483 |
empty.]} |
| 484 |
|
| 485 |
@ChgRef{Version=[2],Kind=[Added]} |
| 486 |
@ChgAdded{Version=[2],Text=[A library @nt{package_declaration} is the completion of |
| 487 |
the declaration of its limited view.]} |
| 488 |
|
| 489 |
@begin{Honest} |
| 490 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 491 |
@ChgAdded{Version=[2],Text=[This is notwithstanding the rule in |
| 492 |
@RefSecNum{Completions of Declarations} that says that implicit declarations |
| 493 |
don't have completions.]} |
| 494 |
@end{Honest} |
| 495 |
@begin{Reason} |
| 496 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 497 |
@ChgAdded{Version=[2],Text=[This rule explains where to find the completions |
| 498 |
of the incomplete views defined by the limited view.]} |
| 499 |
@end{Reason} |
| 500 |
|
| 501 |
@end{Intro} |
| 502 |
|
| 503 |
@begin{Legality} |
| 504 |
The parent unit of a @nt<library_item> shall be a |
| 505 |
@Redundant[library] package or generic @Redundant[library] package. |
| 506 |
|
| 507 |
If a @nt{defining_program_unit_name} of a given |
| 508 |
declaration or body has a @nt{parent_unit_name}, |
| 509 |
then the given declaration or body shall be a @nt<library_item>. |
| 510 |
The body of a program unit shall be a @nt{library_item} if and only |
| 511 |
if the declaration of the program unit is a @nt<library_item>. |
| 512 |
In a @nt{library_@!unit_@!renaming_@!declaration}, |
| 513 |
the @Redundant[(old)] @nt{name} |
| 514 |
shall denote a @nt<library_item>. |
| 515 |
@begin{Discussion} |
| 516 |
We could have allowed nested program units to be children |
| 517 |
of other program units; |
| 518 |
their semantics would make sense. |
| 519 |
We disallow them to keep things simpler |
| 520 |
and because they wouldn't be particularly useful. |
| 521 |
@end{Discussion} |
| 522 |
|
| 523 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 524 |
A @nt{parent_unit_name} @Redundant[(which can be used within a |
| 525 |
@nt<defining_program_unit_name> of a @nt<library_item> |
| 526 |
and in the @key[separate] clause of a @nt<subunit>)], |
| 527 |
and each of its @nt{prefix}es, |
| 528 |
shall not denote a @nt{renaming_declaration}. |
| 529 |
@Redundant[On the other hand, |
| 530 |
a name that denotes a @nt{library_@!unit_@!renaming_@!declaration} is allowed |
| 531 |
in a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]} |
| 532 |
and other places where the name of a library unit is allowed.] |
| 533 |
|
| 534 |
If a library package is an instance of |
| 535 |
a generic package, then every child of the |
| 536 |
library package shall either be itself an instance or be a renaming of |
| 537 |
a library unit. |
| 538 |
@begin{Discussion} |
| 539 |
A child of an instance of a given generic unit |
| 540 |
will often be an instance of a (generic) child of the given |
| 541 |
generic unit. |
| 542 |
This is not required, however. |
| 543 |
@end{Discussion} |
| 544 |
@begin{Reason} |
| 545 |
@leading@;Instances are forbidden from having noninstance children for two reasons: |
| 546 |
@begin(Enumerate) |
| 547 |
We want all source code that can depend on information from |
| 548 |
the private part of a library unit to be inside the "subsystem" |
| 549 |
rooted at the library unit. |
| 550 |
If an instance of a generic unit were allowed to have a noninstance |
| 551 |
as a child, the source code of that child might depend on information |
| 552 |
from the private part of the generic unit, even though it is outside |
| 553 |
the subsystem rooted at the generic unit. |
| 554 |
|
| 555 |
Disallowing noninstance children simplifies the description of the |
| 556 |
semantics of children of generic packages. |
| 557 |
@end(Enumerate) |
| 558 |
@end{Reason} |
| 559 |
|
| 560 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]} |
| 561 |
A child of a generic library package shall either be itself a generic unit |
| 562 |
or be a renaming of some other child of the same generic unit.@Chg{Version=[3], |
| 563 |
New=[],Old=[ The renaming of a child of a generic package shall occur |
| 564 |
only within the declarative region of the generic package.]} |
| 565 |
|
| 566 |
|
| 567 |
A child of a parent generic package shall be |
| 568 |
instantiated or renamed only within the declarative region |
| 569 |
of the parent generic. |
| 570 |
|
| 571 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00331-01]} |
| 572 |
For each @Chg{Version=[2],New=[child @i<C>], |
| 573 |
Old=[declaration or renaming of a generic unit as a child]} of some parent |
| 574 |
generic package@Chg{Version=[2],New=[ @i<P>],Old=[]}, there is |
| 575 |
a corresponding declaration @Chg{Version=[2],New=[@i<C>],Old=[]} nested |
| 576 |
immediately within each instance @Chg{Version=[2],New=[of @i<P>. For the |
| 577 |
purposes of this rule, if a child @i<C> itself has a child @i<D>, each |
| 578 |
corresponding declaration for @i<C> has a corresponding |
| 579 |
child @i<D>], Old=[of the parent]}. |
| 580 |
@Redundant[@Chg{Version=[2],New=[The corresponding],Old=[This]} |
| 581 |
declaration @Chg{Version=[2],New=[for a child within an instance ],Old=[]}is |
| 582 |
visible only within the scope of a @nt{with_clause} that |
| 583 |
mentions the @Chg{Version=[2],New=[(original) ],Old=[]}child generic unit.] |
| 584 |
|
| 585 |
@begin{ImplNote} |
| 586 |
Within the child, like anything nested in a generic unit, |
| 587 |
one can make up-level references to the current instance of its |
| 588 |
parent, and thereby gain access to the formal parameters of the |
| 589 |
parent, to the types declared in the parent, etc. |
| 590 |
This @lquotes@;nesting@rquotes@; model applies even within the |
| 591 |
@nt{generic_formal_part} of the child, |
| 592 |
as it does for a generic child of a nongeneric unit. |
| 593 |
@end{ImplNote} |
| 594 |
@begin{Ramification} |
| 595 |
|
| 596 |
Suppose P is a generic library package, |
| 597 |
and P.C is a generic child of P. |
| 598 |
P.C can be instantiated inside the declarative region of P. |
| 599 |
Outside P, P.C can be mentioned only in a @nt{with_clause}. |
| 600 |
Conceptually, an instance I of P is a package that has a nested |
| 601 |
generic unit called I.C. |
| 602 |
Mentioning P.C in a @nt{with_clause} allows I.C to be instantiated. |
| 603 |
I need not be a library unit, |
| 604 |
and the instantiation of I.C need not be a library unit. |
| 605 |
If I is a library unit, and an instance of I.C is a child of I, |
| 606 |
then this instance has to be called something other than C. |
| 607 |
|
| 608 |
@end{Ramification} |
| 609 |
|
| 610 |
A library subprogram shall not override a primitive subprogram. |
| 611 |
@begin{Reason} |
| 612 |
This prevents certain obscure anomalies. |
| 613 |
For example, if a library subprogram were to override a subprogram |
| 614 |
declared in its parent package, then in a compilation unit that depends |
| 615 |
@i{in}directly on the library subprogram, the library subprogram could |
| 616 |
hide the overridden operation from all visibility, |
| 617 |
but the library subprogram itself would not be visible. |
| 618 |
|
| 619 |
Note that even without this rule, such subprograms would be illegal for |
| 620 |
tagged types, because of the freezing rules. |
| 621 |
@end{Reason} |
| 622 |
|
| 623 |
The defining name of a function that is a compilation unit |
| 624 |
shall not be an @nt{operator_symbol}. |
| 625 |
@begin{Reason} |
| 626 |
Since overloading is not permitted among compilation units, |
| 627 |
it seems unlikely that it would be useful to define one as |
| 628 |
an operator. Note that a subunit could be renamed within its |
| 629 |
parent to be an operator. |
| 630 |
@end{Reason} |
| 631 |
|
| 632 |
@end{Legality} |
| 633 |
|
| 634 |
@begin{StaticSem} |
| 635 |
|
| 636 |
A @nt<subprogram_renaming_declaration> |
| 637 |
that is a @nt{library_@!unit_@!renaming_@!declaration} is a |
| 638 |
renaming-as-declaration, not a renaming-as-body. |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
@leading@keepnext@redundant[There are two kinds of dependences among |
| 643 |
compilation units:] |
| 644 |
@begin{Itemize} |
| 645 |
@redundant[The @i{semantic dependences} |
| 646 |
(see below) |
| 647 |
are the ones needed to check the |
| 648 |
compile-time rules across compilation unit boundaries; |
| 649 |
a compilation unit depends semantically on |
| 650 |
the other compilation units needed to determine its legality. |
| 651 |
The visibility rules are based on the semantic dependences. |
| 652 |
|
| 653 |
The @i{elaboration dependences} |
| 654 |
(see @RefSecNum{Program Execution}) |
| 655 |
determine the order of elaboration of @nt{library_item}s.] |
| 656 |
@end{Itemize} |
| 657 |
@begin{Discussion} |
| 658 |
Don't confuse these kinds of dependences with the run-time |
| 659 |
dependences among tasks and masters defined in |
| 660 |
@RefSec{Task Dependence - Termination of Tasks}. |
| 661 |
@end{Discussion} |
| 662 |
|
| 663 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 664 |
@Defn2{Term=[semantic dependence], Sec=(of one compilation unit upon another)} |
| 665 |
@Defn2{Term=[dependence], Sec=(semantic)} |
| 666 |
A @nt{library_item} depends semantically upon its |
| 667 |
parent declaration. |
| 668 |
A subunit depends semantically upon its parent body. |
| 669 |
A @nt{library_unit_body} depends semantically upon the corresponding |
| 670 |
@nt{library_unit_declaration}, if any. |
| 671 |
@Chg{Version=[2],New=[The declaration of the limited view of a |
| 672 |
library package depends semantically upon the declaration of the |
| 673 |
limited view of its parent. |
| 674 |
The declaration of a library package depends semantically upon the |
| 675 |
declaration of its limited view.],Old=[]} |
| 676 |
A compilation unit depends semantically upon each @nt<library_item> |
| 677 |
mentioned in a @nt{with_clause} of the compilation unit. |
| 678 |
In addition, if a given compilation unit contains an @nt{attribute_reference} |
| 679 |
of a type defined in another compilation unit, |
| 680 |
then the given compilation unit depends semantically upon the |
| 681 |
other compilation unit. |
| 682 |
The semantic dependence relationship is transitive. |
| 683 |
|
| 684 |
@begin{Discussion} |
| 685 |
The @lquotes@;if any@rquotes@; in the third sentence is necessary |
| 686 |
because library subprograms are not required to have a |
| 687 |
@nt{subprogram_declaration}. |
| 688 |
@end{Discussion} |
| 689 |
@begin{Honest} |
| 690 |
If a given compilation unit contains a |
| 691 |
@nt{choice_parameter_specification}, |
| 692 |
then the given compilation unit depends semantically upon the |
| 693 |
declaration of Ada.Exceptions. |
| 694 |
|
| 695 |
If a given compilation unit contains a @nt{pragma} with an |
| 696 |
argument of a type defined in another compilation unit, |
| 697 |
then the given compilation unit depends semantically upon the |
| 698 |
other compilation unit. |
| 699 |
@end{Honest} |
| 700 |
@begin{Discussion} |
| 701 |
For example, a compilation unit containing |
| 702 |
X'Address depends semantically upon the declaration of package |
| 703 |
System. |
| 704 |
|
| 705 |
For the Address attribute, this fixes a hole in Ada 83. |
| 706 |
Note that in almost all cases, the dependence will need to exist |
| 707 |
due to @nt{with_clause}s, even without this rule. |
| 708 |
Hence, the rule has very little effect on programmers. |
| 709 |
|
| 710 |
Note that the semantic dependence does not have the same effect as a |
| 711 |
@nt{with_clause}; in order to denote a declaration in one of those |
| 712 |
packages, a @nt{with_clause} will generally be needed. |
| 713 |
|
| 714 |
Note that no special rule is needed for an |
| 715 |
@nt{attribute_definition_clause}, since an expression after @key[use] |
| 716 |
will require semantic dependence upon the compilation unit containing |
| 717 |
the @nt{type_declaration} of interest. |
| 718 |
|
| 719 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 720 |
@ChgAdded{Version=[2],Text=[Unlike a full view of a package, a limited view |
| 721 |
does not depend semantically on units mentioned in @nt{with_clause}s of the |
| 722 |
@nt{compilation_unit} that defines the package. Formally, this is |
| 723 |
achieved by saying that the limited view has an empty @nt{context_clause}. |
| 724 |
This is necessary so that they |
| 725 |
can be useful for their intended purpose: allowing mutual dependences between |
| 726 |
packages. The lack of semantic dependence limits the contents of a limited view |
| 727 |
to the items that can be determined solely from the syntax of the source of the |
| 728 |
package, without any semantic analysis. That allows it to be created without |
| 729 |
the semantic dependences of a full package.]} |
| 730 |
@end{Discussion} |
| 731 |
@end{StaticSem} |
| 732 |
|
| 733 |
@begin{RunTime} |
| 734 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 735 |
@ChgAdded{Version=[2],Text=[The elaboration of the declaration of the limited |
| 736 |
view of a package has no effect.]} |
| 737 |
@end{RunTime} |
| 738 |
|
| 739 |
@begin{Notes} |
| 740 |
A simple program may consist of a single compilation unit. |
| 741 |
A @nt{compilation} need not have any compilation units; |
| 742 |
for example, its text can consist of @nt{pragma}s. |
| 743 |
@begin{Ramification} |
| 744 |
Such @nt{pragma}s cannot have any arguments that are @nt{name}s, |
| 745 |
by a previous rule of this subclause. |
| 746 |
A @nt{compilation} can even be entirely empty, |
| 747 |
which is probably not useful. |
| 748 |
|
| 749 |
Some interesting properties of the three kinds of dependence: |
| 750 |
The elaboration dependences also include the semantic dependences, |
| 751 |
except that subunits are taken together with their parents. |
| 752 |
The semantic dependences partly determine the order in which the |
| 753 |
compilation units appear in the environment at compile time. |
| 754 |
At run time, the order is partly determined by the elaboration |
| 755 |
dependences. |
| 756 |
|
| 757 |
@leading@;The model whereby a child is inside its parent's declarative region, |
| 758 |
after the parent's declaration, |
| 759 |
as explained in @RefSecNum{Declarative Region}, |
| 760 |
has the following ramifications: |
| 761 |
@begin(itemize) |
| 762 |
The restrictions on @lquotes@;early@rquotes@; use of a private type (RM83-7.4.1(4)) |
| 763 |
or a deferred constant (RM83-7.4.3(2)) |
| 764 |
do not apply to uses in child units, because they follow |
| 765 |
the full declaration. |
| 766 |
|
| 767 |
A library subprogram is never primitive, even if its profile includes a |
| 768 |
type declared immediately within the parent's @nt{package_specification}, |
| 769 |
because the child is not declared immediately within the same |
| 770 |
@nt{package_specification} as the type (so it doesn't declare a new |
| 771 |
primitive subprogram), and because the child is forbidden from overriding |
| 772 |
an old primitive subprogram. It is immediately within the same declarative |
| 773 |
region, but not the same @nt{package_specification}. Thus, for a tagged type, |
| 774 |
it is not possible to call a child subprogram in a dispatching manner. |
| 775 |
(This is also forbidden by the freezing rules.) |
| 776 |
Similarly, it is not possible for the user to declare primitive |
| 777 |
subprograms of the types declared in the declaration of Standard, |
| 778 |
such as Integer (even if the rules were changed to allow a library unit |
| 779 |
whose name is an operator symbol). |
| 780 |
|
| 781 |
When the parent unit is @lquotes@;used@rquotes@; the simple names of the |
| 782 |
with'd child units are directly visible (see @RefSec{Use Clauses}). |
| 783 |
|
| 784 |
When a parent body with's its own child, the defining name of |
| 785 |
the child is directly visible, and the parent body |
| 786 |
is not allowed to |
| 787 |
include a declaration of a homograph of the child unit |
| 788 |
immediately within the @nt{declarative_part} of the body |
| 789 |
(RM83-8.3(17)). |
| 790 |
@end(itemize) |
| 791 |
|
| 792 |
Note that @lquotes@;declaration of a library unit@rquotes@; |
| 793 |
is different from @lquotes@;@nt{library_unit_declaration}@rquotes@; |
| 794 |
@em the former includes @nt{subprogram_body}. |
| 795 |
Also, we sometimes really mean @lquotes@;declaration of a view of a |
| 796 |
library unit@rquotes@;, which includes |
| 797 |
@nt{library_@!unit_@!renaming_@!declaration}s. |
| 798 |
|
| 799 |
The visibility rules generally imply that the renamed view of a |
| 800 |
@nt{library_@!unit_@!renaming_@!declaration} has to be mentioned in a |
| 801 |
@nt{with_@!clause} of the @nt{library_@!unit_@!renaming_@!declaration}. |
| 802 |
@end{Ramification} |
| 803 |
@begin{Honest} |
| 804 |
The real rule is that the renamed library unit |
| 805 |
has to be visible in the @nt{library_@!unit_@!renaming_@!declaration}. |
| 806 |
@end{Honest} |
| 807 |
@begin{Reason} |
| 808 |
In most cases, @lquotes@;has to be visible@rquotes@; means there has to be a |
| 809 |
@nt{with_clause}. |
| 810 |
However, it is possible in obscure cases to avoid the need for a |
| 811 |
@nt{with_clause}; in particular, a compilation unit such as |
| 812 |
@lquotes@;@key[package] P.Q @key[renames] P;@rquotes@; |
| 813 |
is legal with no @nt{with_clause}s |
| 814 |
(though not particularly interesting). |
| 815 |
ASCII is physically nested in Standard, |
| 816 |
and so is not a library unit, |
| 817 |
and cannot be renamed as a library unit. |
| 818 |
@end{Reason} |
| 819 |
|
| 820 |
The @nt{designator} of a library function cannot be an @nt{operator_symbol}, |
| 821 |
but a nonlibrary @nt{renaming_declaration} is allowed to rename a library |
| 822 |
function as an operator. |
| 823 |
Within a partition, |
| 824 |
two library subprograms are required to have distinct |
| 825 |
names and hence cannot overload each other. |
| 826 |
However, |
| 827 |
@nt{renaming_declaration}s are allowed to define overloaded names for |
| 828 |
such subprograms, and a locally declared subprogram is allowed to |
| 829 |
overload a library subprogram. The expanded name Standard.L can be |
| 830 |
used to denote a root library unit L (unless the declaration of |
| 831 |
Standard is hidden) |
| 832 |
since root library unit declarations occur immediately within the |
| 833 |
declarative region of package Standard. |
| 834 |
@end{Notes} |
| 835 |
|
| 836 |
@begin{Examples} |
| 837 |
@leading@keepnext@i{Examples of library units:} |
| 838 |
@begin{Example} |
| 839 |
@key[package] Rational_Numbers.IO @key[is] --@RI[ public child of Rational_Numbers, see @RefSecNum{Package Specifications and Declarations}] |
| 840 |
@key[procedure] Put(R : @key[in] Rational); |
| 841 |
@key[procedure] Get(R : @key[out] Rational); |
| 842 |
@key[end] Rational_Numbers.IO; |
| 843 |
|
| 844 |
@key[private procedure] Rational_Numbers.Reduce(R : @key[in out] Rational); |
| 845 |
--@RI[ private child of Rational_Numbers] |
| 846 |
|
| 847 |
@key[with] Rational_Numbers.Reduce; --@RI[ refer to a private child] |
| 848 |
@key[package body] Rational_Numbers @key[is] |
| 849 |
... |
| 850 |
@key[end] Rational_Numbers; |
| 851 |
|
| 852 |
@key[with] Rational_Numbers.IO; @key[use] Rational_Numbers; |
| 853 |
@key[with] Ada.Text_io; --@RI[ see @RefSecNum{Text Input-Output}] |
| 854 |
@key[procedure] Main @key[is] --@RI[ a root library procedure] |
| 855 |
R : Rational; |
| 856 |
@key[begin] |
| 857 |
R := 5/3; --@RI[ construct a rational number, see @RefSecNum{Package Specifications and Declarations}] |
| 858 |
Ada.Text_IO.Put("The answer is: "); |
| 859 |
IO.Put(R); |
| 860 |
Ada.Text_IO.New_Line; |
| 861 |
@key[end] Main; |
| 862 |
|
| 863 |
@key[with] Rational_Numbers.IO; |
| 864 |
@key[package] Rational_IO @key[renames] Rational_Numbers.IO; |
| 865 |
--@RI[ a library unit renaming declaration] |
| 866 |
@end{Example} |
| 867 |
|
| 868 |
Each of the above @nt{library_item}s can be submitted to the compiler |
| 869 |
separately. |
| 870 |
@begin{Discussion} |
| 871 |
@leading@keepnext@i{Example of a generic package with children:} |
| 872 |
|
| 873 |
@begin{Example} |
| 874 |
@key[generic] |
| 875 |
@key[type] Element @key[is] @key[private]; |
| 876 |
@key[with] @key[function] Image(E : Element) @key[return] String; |
| 877 |
@key[package] Generic_Bags @key[is] |
| 878 |
@key[type] Bag @key[is] @key[limited] @key[private]; --@RI{ A bag of Elements.} |
| 879 |
@key[procedure] Add(B : @key[in] @key[out] Bag; E : Element); |
| 880 |
@key[function] Bag_Image(B : Bag) @key[return] String; |
| 881 |
@key[private] |
| 882 |
@key[type] Bag @key[is] ...; |
| 883 |
@key[end] Generic_Bags; |
| 884 |
|
| 885 |
@key[generic] |
| 886 |
@key[package] Generic_Bags.Generic_Iterators @key[is] |
| 887 |
... --@RI{ various additional operations on Bags.} |
| 888 |
|
| 889 |
@key[generic] |
| 890 |
@key[with] @key[procedure] Use_Element(E : @key[in] Element); |
| 891 |
--@RI{ Called once per bag element.} |
| 892 |
@key[procedure] Iterate(B : @key[in] Bag); |
| 893 |
@key[end] Generic_Bags.Generic_Iterators; |
| 894 |
@end{Example} |
| 895 |
|
| 896 |
@begin{WideAbove} |
| 897 |
@leading@keepnext@;A package that instantiates the above generic units: |
| 898 |
@end{WideAbove} |
| 899 |
@begin{Example} |
| 900 |
@key[with] Generic_Bags; |
| 901 |
@key[with] Generic_Bags.Generic_Iterators; |
| 902 |
@key[package] My_Abstraction @key[is] |
| 903 |
@key[type] My_Type @key[is] ...; |
| 904 |
@key[function] Image(X : My_Type) @key[return] String; |
| 905 |
@key[package] Bags_Of_My_Type @key[is] @key[new] Generic_Bags(My_Type, Image); |
| 906 |
@key[package] Iterators_Of_Bags_Of_My_Type @key[is] @key[new] Bags_Of_My_Type.Generic_Iterators; |
| 907 |
@key[end] My_Abstraction; |
| 908 |
@end{Example} |
| 909 |
|
| 910 |
In the above example, Bags_Of_My_Type has a nested generic unit called |
| 911 |
Generic_Iterators. |
| 912 |
The second @nt{with_clause} makes that nested unit visible. |
| 913 |
|
| 914 |
@leading@;Here we show how the generic body could depend on one of its own |
| 915 |
children: |
| 916 |
@begin{Example} |
| 917 |
@key[with] Generic_Bags.Generic_Iterators; |
| 918 |
@key[package] @key[body] Generic_Bags @key[is] |
| 919 |
@key[procedure] Add(B : @key[in] @key[out] Bag; E : Element) @key[is] ... @key[end] Add; |
| 920 |
|
| 921 |
@key[package] Iters @key[is] @key[new] Generic_Iterators; |
| 922 |
|
| 923 |
@key[function] Bag_Image(B : Bag) @key[return] String @key[is] |
| 924 |
Buffer : String(1..10_000); |
| 925 |
Last : Integer := 0; |
| 926 |
|
| 927 |
@key[procedure] Append_Image(E : @key[in] Element) @key[is] |
| 928 |
Im : @key[constant] String := Image(E); |
| 929 |
@key[begin] |
| 930 |
@key[if] Last /= 0 @key[then] --@RI{ Insert a comma.} |
| 931 |
Last := Last + 1; |
| 932 |
Buffer(Last) := ','; |
| 933 |
@key[end] @key[if]; |
| 934 |
Buffer(Last+1 .. Last+Im'Length) := Im; |
| 935 |
Last := Last + Im'Length; |
| 936 |
@key[end] Append_Image; |
| 937 |
|
| 938 |
@key[procedure] Append_All @key[is] @key[new] Iters.Iterate(Append_Image); |
| 939 |
@key[begin] |
| 940 |
Append_All(B); |
| 941 |
@key[return] Buffer(1..Last); |
| 942 |
@key[end] Bag_Image; |
| 943 |
@key[end] Generic_Bags; |
| 944 |
@end{Example} |
| 945 |
|
| 946 |
@end{Discussion} |
| 947 |
@end{Examples} |
| 948 |
|
| 949 |
@begin{Extend83} |
| 950 |
@Defn{extensions to Ada 83} |
| 951 |
The syntax rule for @nt{library_item} is modified to allow the |
| 952 |
reserved word @key{private} before a @nt{library_unit_declaration}. |
| 953 |
|
| 954 |
Children (other than children of Standard) |
| 955 |
are new in Ada 95. |
| 956 |
|
| 957 |
Library unit renaming is new in Ada 95. |
| 958 |
@end{Extend83} |
| 959 |
|
| 960 |
@begin{DiffWord83} |
| 961 |
Standard is considered a library unit in Ada 95. |
| 962 |
This simplifies the descriptions, |
| 963 |
since it implies that the parent of each library unit is a library unit. |
| 964 |
(Standard itself has no parent, of course.) |
| 965 |
As in Ada 83, the language does not define any way to recompile |
| 966 |
Standard, since the name given in the declaration of a library unit is |
| 967 |
always interpreted in relation to Standard. |
| 968 |
That is, |
| 969 |
an attempt to compile a package Standard would result in |
| 970 |
Standard.Standard. |
| 971 |
@end{DiffWord83} |
| 972 |
|
| 973 |
@begin{Extend95} |
| 974 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 975 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 976 |
The concept of a limited view is new. Combined with @nt{limited_with_clause}s |
| 977 |
(see @RefSecNum{Context Clauses - With Clauses}), they facilitate |
| 978 |
construction of mutually recursive types in multiple packages.]} |
| 979 |
@end{Extend95} |
| 980 |
|
| 981 |
@begin{DiffWord95} |
| 982 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00331-01]} |
| 983 |
@ChgAdded{Version=[2],Text=[Clarified the wording so that a grandchild |
| 984 |
generic unit will work as expected.]} |
| 985 |
@end{DiffWord95} |
| 986 |
|
| 987 |
@begin{DiffWord2005} |
| 988 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0108-1],ARef=[AI05-0129-1]} |
| 989 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Clarified the wording so that |
| 990 |
it is clear that limited views of types never have discriminants and never |
| 991 |
are of incomplete types.]} |
| 992 |
@end{DiffWord2005} |
| 993 |
|
| 994 |
|
| 995 |
@LabeledSubClause{Context Clauses - With Clauses} |
| 996 |
|
| 997 |
@begin{Intro} |
| 998 |
@redundant[A @nt{context_clause} is used to specify |
| 999 |
the @nt<library_item>s whose |
| 1000 |
names are needed within a compilation unit.] |
| 1001 |
@end{Intro} |
| 1002 |
|
| 1003 |
@begin{MetaRules} |
| 1004 |
@Defn{one-pass @nt{context_clause}s} |
| 1005 |
The reader should be able to understand a @nt{context_clause} without |
| 1006 |
looking ahead. |
| 1007 |
Similarly, when compiling a @nt{context_clause}, |
| 1008 |
the compiler should not have to look ahead at |
| 1009 |
subsequent @nt{context_item}s, nor at the compilation unit |
| 1010 |
to which the @nt{context_clause} is attached. |
| 1011 |
(We have not completely achieved this.) |
| 1012 |
|
| 1013 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1014 |
@ChgAdded{Version=[2],Text=[@Defn{ripple effect}A @i<ripple effect> occurs |
| 1015 |
when the legality of a compilation unit could be affected by adding or removing |
| 1016 |
an otherwise unneeded @nt{with_clause} on some compilation unit on which the |
| 1017 |
unit depends, directly or indirectly. We try to avoid ripple effects because |
| 1018 |
they make understanding and maintenance more difficult. However, ripple effects |
| 1019 |
can occur because of direct visibility (as in child units); this seems |
| 1020 |
impossible to eliminate. The ripple effect for @nt{with_clause}s is somewhat |
| 1021 |
similar to the Beaujolais effect (see @RefSecNum{Use Clauses}) for |
| 1022 |
@nt{use_clause}s, which we also try to avoid.]} |
| 1023 |
@end{MetaRules} |
| 1024 |
|
| 1025 |
@begin{Syntax} |
| 1026 |
@Syn{lhs=<context_clause>,rhs="{@Syn2{context_item}}"} |
| 1027 |
|
| 1028 |
|
| 1029 |
@Syn{lhs=<context_item>,rhs="@Syn2{with_clause} | @Syn2{use_clause}"} |
| 1030 |
|
| 1031 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00262-01]} |
| 1032 |
@Syn{lhs=<with_clause>,rhs="@Chg{Version=[2],New=<@Syn2{limited_with_clause} | @Syn2{nonlimited_with_clause}>,Old=<@key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>}"} |
| 1033 |
|
| 1034 |
@ChgRef{Version=[2],Kind=[Added]} |
| 1035 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<limited_with_clause>,Old=<>}>,rhs="@Chg{Version=[2],New=<@key{limited} [@key{private}] @key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>,Old=<>}"} |
| 1036 |
|
| 1037 |
@ChgRef{Version=[2],Kind=[Added]} |
| 1038 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<nonlimited_with_clause>,Old=<>}>,rhs="@Chg{Version=[2],New=<[@key{private}] @key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>,Old=<>}"} |
| 1039 |
|
| 1040 |
@begin{Discussion} |
| 1041 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1042 |
@ChgAdded{Version=[2],Text=[A @nt{limited_with_clause} makes a limited view |
| 1043 |
of a unit visible.]} |
| 1044 |
|
| 1045 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]} |
| 1046 |
@ChgAdded{Version=[2],Text=[@Defn{private with_clause}A @nt{with_clause} |
| 1047 |
containing the reserved word @key{private} is called a @i{private with_clause}. |
| 1048 |
It can be thought of as making items visible only in the private part, although |
| 1049 |
it really |
| 1050 |
makes items visible everywhere except the visible part. It can be used both for |
| 1051 |
documentation purposes (to say that a unit is not used in the visible part), |
| 1052 |
and to allow access to private units that otherwise would be |
| 1053 |
prohibited.]} |
| 1054 |
@end{Discussion} |
| 1055 |
@end{Syntax} |
| 1056 |
|
| 1057 |
@begin{Resolution} |
| 1058 |
@Defn2{Term=[scope], Sec=(of a @nt{with_clause})} |
| 1059 |
The @i{scope} of a @nt{with_clause} that appears on a |
| 1060 |
@nt{library_@!unit_@!declaration} |
| 1061 |
or @nt{library_@!unit_@!renaming_@!declaration} |
| 1062 |
consists of the entire declarative region of the declaration@Redundant[, |
| 1063 |
which includes all children and subunits]. |
| 1064 |
The scope of a @nt{with_clause} that appears on a |
| 1065 |
body consists of the body@Redundant[, which includes all subunits]. |
| 1066 |
@begin{Discussion} |
| 1067 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]} |
| 1068 |
Suppose a @Chg{Version=[2],New=[nonprivate ],Old=[]} @nt{with_clause} of a |
| 1069 |
public library unit mentions one of its private siblings. |
| 1070 |
(This is only allowed on the body of the public library unit.) |
| 1071 |
We considered making the scope of that @nt{with_clause} |
| 1072 |
not include the visible part of the public library unit. |
| 1073 |
(This would only matter for a @nt{subprogram_body}, |
| 1074 |
since those are the only kinds of body that have a visible part, |
| 1075 |
and only if the @nt{subprogram_body} completes a |
| 1076 |
@nt{subprogram_declaration}, since otherwise the @nt{with_clause} |
| 1077 |
would be illegal.) |
| 1078 |
We did not put in such a rule for two reasons: |
| 1079 |
(1) It would complicate the wording of the rules, |
| 1080 |
because we would have to split each @nt{with_clause} |
| 1081 |
into pieces, in order to correctly handle @lquotes@;@key[with] P, Q;@rquotes@; |
| 1082 |
where P is public and Q is private. |
| 1083 |
(2) The conformance rules prevent any problems. |
| 1084 |
It doesn't matter if a type name in the spec of the body denotes |
| 1085 |
the completion of a @nt{private_type_declaration}. |
| 1086 |
|
| 1087 |
A @nt{with_clause} also affects visibility within subsequent |
| 1088 |
@nt{use_clause}s and @nt{pragma}s of the same @nt{context_clause}, |
| 1089 |
even though those are not in the scope of the @nt{with_clause}. |
| 1090 |
@end{Discussion} |
| 1091 |
|
| 1092 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 1093 |
@Defn2{Term=[mentioned],Sec=[in a @nt<with_clause>]} |
| 1094 |
@Defn2{Term=[with_clause], Sec=(mentioned in)} |
| 1095 |
A @nt<library_item> @Chg{Version=[2],New=[(and the corresponding library |
| 1096 |
unit) ],Old=[]}is |
| 1097 |
@Chg{Version=[2],New=[@i{named} |
| 1098 |
@Defn2{Term=[named],Sec=[in a @nt<with_clause>]} |
| 1099 |
@Defn2{Term=[with_clause], Sec=(named in)}],Old=[@i{mentioned} ]}in a |
| 1100 |
@nt<with_clause> if it is denoted by |
| 1101 |
a @i(library_unit_)@nt<name> @Chg{Version=[2],New=[],Old=[or a @nt<prefix> ]} |
| 1102 |
in the @nt<with_clause>. |
| 1103 |
@Chg{Version=[2],New=[A @nt{library_item} (and the corresponding library unit) |
| 1104 |
is @i<mentioned> in a @nt{with_clause} |
| 1105 |
if it is named in the @nt{with_clause} or if it is denoted by a @nt{prefix} in |
| 1106 |
the @nt{with_clause}.],Old=[]} |
| 1107 |
|
| 1108 |
@begin{Discussion} |
| 1109 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 1110 |
@nt{With_clause}s control the visibility of |
| 1111 |
declarations or renamings of library units. |
| 1112 |
Mentioning a root library unit in a |
| 1113 |
@nt{with_clause} makes its declaration |
| 1114 |
directly visible. Mentioning a nonroot library unit |
| 1115 |
makes its declaration visible. |
| 1116 |
See @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Visibility Rules} |
| 1117 |
for details. |
| 1118 |
|
| 1119 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 1120 |
Note that this rule implies that @lquotes@;@key{with} A.B.C;@rquotes@; is |
| 1121 |
@chg{Version=[2],New=[almost ],Old=[]}equivalent to |
| 1122 |
@lquotes@;@key{with} A, A.B, A.B.C;@rquotes@;@Chg{Version=[2],New=[.],Old=[]} |
| 1123 |
The reason for making a @nt{with_clause} apply to all the ancestor |
| 1124 |
units is to avoid @lquotes@;visibility holes@rquotes@; @em situations in which an inner |
| 1125 |
program unit is visible while an outer one is not. |
| 1126 |
Visibility holes would cause semantic complexity and implementation |
| 1127 |
difficulty.@Chg{Version=[2],New=[ (This |
| 1128 |
is not exactly equivalent because the latter @nt{with_clause} names |
| 1129 |
A and A.B, while the previous one does not. Whether a unit is |
| 1130 |
@ldquote@;named@rdquote does not have any effect on visibility, however, |
| 1131 |
so it is equivalent for visibility purposes.)],Old=[]} |
| 1132 |
|
| 1133 |
@end{Discussion} |
| 1134 |
|
| 1135 |
@redundant[Outside its own declarative region, |
| 1136 |
the declaration or renaming of |
| 1137 |
a library unit can be visible only within the scope of a |
| 1138 |
@nt{with_clause} that mentions it. |
| 1139 |
The visibility of the declaration or renaming of a |
| 1140 |
library unit otherwise |
| 1141 |
follows from its placement in the environment.] |
| 1142 |
@end{Resolution} |
| 1143 |
|
| 1144 |
@begin{Legality} |
| 1145 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]} |
| 1146 |
If a @nt{with_clause} of a given @nt<compilation_unit> mentions |
| 1147 |
a private child of some library unit, |
| 1148 |
then the given @nt{compilation_unit} shall be @Chg{Version=[2],New=[one of:], |
| 1149 |
Old=[either the declaration of a private descendant of that library unit |
| 1150 |
or the body or subunit of a @Redundant[(public or private)] descendant of |
| 1151 |
that library unit.]} |
| 1152 |
@begin{Itemize} |
| 1153 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]} |
| 1154 |
@ChgAdded{Version=[2],Text=[the declaration, body, or subunit of a private |
| 1155 |
descendant of that library unit;]} |
| 1156 |
|
| 1157 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00220-01],ARef=[AI95-00262-01]} |
| 1158 |
@ChgAdded{Version=[2],Text=[the body or subunit of a public descendant of that |
| 1159 |
library unit, but not a subprogram body acting as a subprogram declaration (see |
| 1160 |
@RefSecNum{The Compilation Process}); or]} |
| 1161 |
|
| 1162 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]} |
| 1163 |
@ChgAdded{Version=[2],Text=[the declaration of a public descendant of that |
| 1164 |
library unit, in which case the @nt<with_clause> shall include the reserved word |
| 1165 |
@key<private>.]} |
| 1166 |
@end{Itemize} |
| 1167 |
|
| 1168 |
@begin{Reason} |
| 1169 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]} |
| 1170 |
The purpose of this rule is to prevent a private child from being |
| 1171 |
visible @Chg{Version=[2],New=[],Old=[(or even semantically depended-on) ]}from |
| 1172 |
outside the subsystem rooted at its parent. @Chg{Version=[2],New=[A private |
| 1173 |
child can be semantically depended-on without violating this principle if it is |
| 1174 |
used in a private @nt{with_clause}.],Old=[]} |
| 1175 |
@end{Reason} |
| 1176 |
@begin{Discussion} |
| 1177 |
This rule violates the one-pass @nt{context_clause}s |
| 1178 |
@MetaRulesName. We rationalize this by saying that at least that |
| 1179 |
@MetaRulesName works for legal compilation units. |
| 1180 |
|
| 1181 |
@leading@keepnext@;Example: |
| 1182 |
@begin{Example} |
| 1183 |
@key[package] A @key[is] |
| 1184 |
@key[end] A; |
| 1185 |
|
| 1186 |
@key[package] A.B @key[is] |
| 1187 |
@key[end] A.B; |
| 1188 |
|
| 1189 |
@key[private] @key[package] A.B.C @key[is] |
| 1190 |
@key[end] A.B.C; |
| 1191 |
|
| 1192 |
@key[package] A.B.C.D @key[is] |
| 1193 |
@key[end] A.B.C.D; |
| 1194 |
|
| 1195 |
@key[with] A.B.C; -- @RI[(1)] |
| 1196 |
@key[private] @key[package] A.B.X @key[is] |
| 1197 |
@key[end] A.B.X; |
| 1198 |
|
| 1199 |
@key[package] A.B.Y @key[is] |
| 1200 |
@key[end] A.B.Y; |
| 1201 |
|
| 1202 |
@key[with] A.B.C; -- @RI[(2)] |
| 1203 |
@key[package] @key[body] A.B.Y @key[is] |
| 1204 |
@key[end] A.B.Y; |
| 1205 |
|
| 1206 |
@ChgRef{Version=[2],Kind=[Added]}@ChgAdded{Version=[2],Text=[@key[private] @key[with] A.B.C; -- @RI[(3)] |
| 1207 |
@key[package] A.B.Z @key[is] |
| 1208 |
@key[end] A.B.Z;]} |
| 1209 |
@end{Example} |
| 1210 |
|
| 1211 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]} |
| 1212 |
(1) is OK because it's a private child of A.B @em it would be illegal if |
| 1213 |
we made A.B.X a public child of A.B. |
| 1214 |
(2) is OK because it's the body of a child of A.B. |
| 1215 |
@Chg{Version=[2],New=[(3) is OK because it's a child of A.B, and it is a |
| 1216 |
private @nt{with_clause}.],Old=[]} |
| 1217 |
It would be illegal to say @lquotes@;@key[with] A.B.C;@rquotes@; on any |
| 1218 |
@nt{library_item} whose name does not start with @lquotes@;A.B@rquotes@;. |
| 1219 |
Note that mentioning A.B.C.D in a @nt{with_clause} automatically |
| 1220 |
mentions A.B.C as well, |
| 1221 |
so @lquotes@;@key[with] A.B.C.D;@rquotes@; is illegal in the same places as |
| 1222 |
@lquotes@;@key[with] A.B.C;@rquotes@;. |
| 1223 |
@end{Discussion} |
| 1224 |
@begin{Honest} |
| 1225 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0005-1]} |
| 1226 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]} |
| 1227 |
@ChgDeleted{Version=[3],Text=[For the purposes of this rule, |
| 1228 |
if a @nt{subprogram_body} has no preceding @nt{subprogram_declaration}, |
| 1229 |
the @nt{subprogram_body} should be considered a declaration and not a body. |
| 1230 |
Thus, it is illegal for such a @nt{subprogram_body} to mention one of |
| 1231 |
its siblings in a @Chg{Version=[2],New=[nonprivate ],Old=[]}@nt{with_clause} |
| 1232 |
if the sibling is a private library unit.]} |
| 1233 |
@end{Honest} |
| 1234 |
|
| 1235 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]} |
| 1236 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0122-1]} |
| 1237 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0261-1]} |
| 1238 |
@ChgAdded{Version=[2],Type=[Leading],Text=[A @nt<name> denoting a |
| 1239 |
@Chg{Version=[3],New=[@nt{library_item} (or the corresponding declaration |
| 1240 |
for a child of a generic within an instance @em see |
| 1241 |
@RefSecNum{Compilation Units - Library Units}), if it],Old=[library item that]} |
| 1242 |
is visible only due to being mentioned in |
| 1243 |
one or more @nt<with_clause>s @Chg{Version=[5],New=[of a unit @i<U> ],Old=[]}that |
| 1244 |
include the reserved word |
| 1245 |
@key<private>@Chg{Version=[3],New=[,],Old=[]} shall appear only within:]} |
| 1246 |
@begin{Itemize} |
| 1247 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1248 |
@ChgAdded{Version=[2],Text=[a private part;]} |
| 1249 |
|
| 1250 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1251 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0261-1]} |
| 1252 |
@ChgAdded{Version=[2],Text=[a body@Chg{Version=[5],New=[ of a public |
| 1253 |
descendant of @i<U>],Old=[]}, but not within the |
| 1254 |
@nt<subprogram_specification> of a @Chg{Version=[5],New=[],Old=[library |
| 1255 |
subprogram ]}body@Chg{Version=[5],New=[ of a subprogram that is a public |
| 1256 |
descendant of @i<U>],Old=[]};]} |
| 1257 |
|
| 1258 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1259 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0261-1]} |
| 1260 |
@ChgAdded{Version=[2],Text=[a private descendant of @Chg{Version=[5],New=[@i<U> |
| 1261 |
or its body],Old=[the unit on which one of these @nt<with_clause>s appear]}; |
| 1262 |
or]} |
| 1263 |
|
| 1264 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1265 |
@ChgAdded{Version=[2],Text=[a pragma within a context clause.]} |
| 1266 |
@end{Itemize} |
| 1267 |
|
| 1268 |
@begin{Ramification} |
| 1269 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1270 |
@ChgAdded{Version=[2],Text=[These rules apply only if all of the |
| 1271 |
@nt{with_clause}s that mention the name include the reserved word |
| 1272 |
@key{private}. They do not apply if the name is mentioned in any |
| 1273 |
@nt{with_clause} that does not include @key{private}.]} |
| 1274 |
@end{Ramification} |
| 1275 |
|
| 1276 |
@begin{Reason} |
| 1277 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1278 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]} |
| 1279 |
@ChgAdded{Version=[2],Text=[These rules make the |
| 1280 |
@Chg{Version=[3],New=[@nt{library_item}],Old=[library item]} |
| 1281 |
visible anywhere that |
| 1282 |
is not visible outside the subsystem rooted at the @nt{compilation_unit} having |
| 1283 |
the private @nt{with_clause}, including private parts of packages |
| 1284 |
nested in the visible part, private parts of child packages, the visible part |
| 1285 |
of private children, and context clause pragmas like Elaborate_All.]} |
| 1286 |
|
| 1287 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1288 |
@ChgAdded{Version=[2],Text=[We considered having the scope of a private |
| 1289 |
@nt{with_clause} not include the visible part. However, that rule would mean |
| 1290 |
that moving a declaration between the visible part and the private part could |
| 1291 |
change its meaning from one legal interpretation to a different legal |
| 1292 |
interpretation. For example:]} |
| 1293 |
@begin{Example} |
| 1294 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1295 |
@ChgAdded{Version=[2],Text=[@key{package} A @key{is} |
| 1296 |
@key{function} B @key{return} Integer; |
| 1297 |
@key{end} A;]} |
| 1298 |
|
| 1299 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1300 |
@ChgAdded{Version=[2],Text=[@key{function} B @key{return} Integer;]} |
| 1301 |
|
| 1302 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1303 |
@ChgAdded{Version=[2],Text=[@key{with} A; |
| 1304 |
@key{private} @key{with} B; |
| 1305 |
@key{package} C @key{is} |
| 1306 |
@key{use} A; |
| 1307 |
V1 : Integer := B; -- (1) |
| 1308 |
@key{private} |
| 1309 |
V2 : Integer := B; -- (2) |
| 1310 |
@key{end} C;]} |
| 1311 |
@end{Example} |
| 1312 |
|
| 1313 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1314 |
@ChgAdded{Version=[2],Text=[If we say that library subprogram B is not in scope |
| 1315 |
in the visible part of C, then the B at (1) resolves to A.B, while (2) |
| 1316 |
resolves to library unit B. Simply moving a declaration could silently change |
| 1317 |
its meaning. With the legality rule defined above, the B at (1) is illegal. |
| 1318 |
If the user really meant A.B, they still can say that.]} |
| 1319 |
@end{Reason} |
| 1320 |
|
| 1321 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1322 |
@ChgAdded{Version=[2],Text=[@Redundant[A @nt{library_item} mentioned in a |
| 1323 |
@nt{limited_with_clause} shall be the implicit declaration of the limited view |
| 1324 |
of a library package, not the declaration of a subprogram, generic unit, |
| 1325 |
generic instance, or a renaming.]]} |
| 1326 |
|
| 1327 |
@begin{TheProof} |
| 1328 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1329 |
@ChgAdded{Version=[2],Text=[This is redundant because only such implicit |
| 1330 |
declarations are visible in a @nt{limited_with_clause}. See |
| 1331 |
@RefSecNum{Environment-Level Visibility Rules}.]} |
| 1332 |
@end{TheProof} |
| 1333 |
|
| 1334 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06],ARef=[AI95-00412-01]} |
| 1335 |
@ChgAdded{Version=[2],Text=[A @nt{limited_with_clause} shall not appear on a |
| 1336 |
@nt{library_unit_body}, @nt{subunit}, or @nt{library_@!unit_@!renaming_@!declaration}.]} |
| 1337 |
|
| 1338 |
@begin{Reason} |
| 1339 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00412-01]} |
| 1340 |
@ChgAdded{Version=[2],Text=[We don't allow a @nt{limited_with_clause} on a |
| 1341 |
@nt{library_@!unit_@!renaming_@!declaration} because it would be useless and |
| 1342 |
therefore probably is a mistake. A |
| 1343 |
renaming cannot appear in a @nt{limited_with_clause} (by the rule prior |
| 1344 |
to this one), and a renaming of a limited view cannot appear in a |
| 1345 |
@nt{nonlimited_with_clause} (because the name |
| 1346 |
would not be within the scope of a @nt{with_clause} denoting the package, see |
| 1347 |
@RefSecNum{Package Renaming Declarations}). Nor could it be the parent of |
| 1348 |
another unit. That doesn't leave anywhere that the name of such a renaming |
| 1349 |
@b<could> appear, so we simply make writing it illegal.]} |
| 1350 |
@end{Reason} |
| 1351 |
|
| 1352 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1353 |
@ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[A |
| 1354 |
@nt{limited_with_clause} that names a library package shall not appear:]} |
| 1355 |
|
| 1356 |
@begin(Itemize) |
| 1357 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1358 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0040-1]} |
| 1359 |
@ChgAdded{Version=[2],Text=[in the @nt{context_clause} for the |
| 1360 |
explicit declaration of the named library package@Chg{Version=[3],New=[ or |
| 1361 |
any of its descendants],Old=[]};]} |
| 1362 |
|
| 1363 |
@begin{Reason} |
| 1364 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1365 |
@ChgAdded{Version=[2],Text=[We have to explicitly disallow]} |
| 1366 |
@begin{Example} |
| 1367 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1368 |
@ChgAdded{Version=[2],Text=[@key{limited} @key{with} P; |
| 1369 |
@key{package} P @key{is} ...]} |
| 1370 |
@end{Example} |
| 1371 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1372 |
@ChgAdded{Version=[2],Text=[as we can't depend on the semantic dependence |
| 1373 |
rules to do it for us as with regular withs. This says @lquotes@;named@rquotes |
| 1374 |
and not @lquotes@;mentioned@rquotes in order that]} |
| 1375 |
@begin{Example} |
| 1376 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1377 |
@ChgAdded{Version=[2],Text=[@key{limited} @key{private} @key{with} P.Child; |
| 1378 |
@key{package} P @key{is} ...]} |
| 1379 |
@end{Example} |
| 1380 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1381 |
@ChgAdded{Version=[2],Text=[can be used to allow a mutual dependence between |
| 1382 |
the private part of P and the private child P.Child, which occurs in |
| 1383 |
interfacing and other problems. Since the child always semantically depends |
| 1384 |
on the parent, this is the only way such a dependence can be broken.]} |
| 1385 |
|
| 1386 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0040-1]} |
| 1387 |
@ChgAdded{Version=[3],Text=[The part about descendants catches examples like]} |
| 1388 |
@begin{Example} |
| 1389 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1390 |
@ChgAdded{Version=[3],Text=[@key{limited} @key{with} P; |
| 1391 |
@key{package} P.Child @key{is} ...]} |
| 1392 |
@end{Example} |
| 1393 |
@end{Reason} |
| 1394 |
|
| 1395 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1396 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0262-1]} |
| 1397 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[within a], Old=[in the same]} |
| 1398 |
@nt{context_clause} |
| 1399 |
@Chg{Version=[3],New=[for a @nt{library_item} that is],Old=[as, or]} |
| 1400 |
within the scope of@Chg{Version=[3],New=[],Old=[,]} |
| 1401 |
a @nt{nonlimited_with_clause} that mentions the same library package; or]} |
| 1402 |
|
| 1403 |
@begin{Ramification} |
| 1404 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0077-1]} |
| 1405 |
@ChgAdded{Version=[3],Text=[This applies to @nt{nonlimited_with_clause}s |
| 1406 |
found in the same @nt{context_clause}, as well as @nt{nonlimited_with_clause}s |
| 1407 |
found on parent units.]} |
| 1408 |
@end{Ramification} |
| 1409 |
|
| 1410 |
@begin{Reason} |
| 1411 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1412 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]} |
| 1413 |
@ChgAdded{Version=[2],Text=[Such a @nt{limited_with_clause} could have no |
| 1414 |
effect, and would be confusing. If@Chg{Version=[3],New=[],Old=[ it is |
| 1415 |
within the scope of]} a @nt{nonlimited_with_clause}@Chg{Version=[3],New=[ |
| 1416 |
for the same package is inherited from a parent unit or given],Old=[, or |
| 1417 |
if such a clause is]} in the @nt{context_clause}, |
| 1418 |
the full view is available, which strictly provides more information than |
| 1419 |
the limited view.]} |
| 1420 |
@end{Reason} |
| 1421 |
|
| 1422 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1423 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0262-1]} |
| 1424 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[within a], Old=[in the same]} |
| 1425 |
@nt{context_clause} |
| 1426 |
@Chg{Version=[3],New=[for a @nt{library_item} that is],Old=[as, or]} |
| 1427 |
within the scope of@Chg{Version=[3],New=[],Old=[,]} |
| 1428 |
a @nt{use_clause} that names an entity declared within the |
| 1429 |
declarative region of the library package.]} |
| 1430 |
|
| 1431 |
@begin{Ramification} |
| 1432 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0077-1]} |
| 1433 |
@ChgAdded{Version=[3],Text=[This applies to @nt{use_clause}s found in the |
| 1434 |
same @nt{context_clause}, as well as @nt{use_clause}s found in (or on) |
| 1435 |
parent units.]} |
| 1436 |
@end{Ramification} |
| 1437 |
|
| 1438 |
@begin{Reason} |
| 1439 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1440 |
@ChgAdded{Version=[2],Text=[This prevents visibility issues, where whether an |
| 1441 |
entity is an incomplete or full view depends on how the name of the entity is |
| 1442 |
written. The @nt{limited_with_clause} cannot be useful, as we must have the |
| 1443 |
full view available in the parent in order for the @nt{use_clause} to be |
| 1444 |
legal.]} |
| 1445 |
@end{Reason} |
| 1446 |
|
| 1447 |
@end(Itemize) |
| 1448 |
|
| 1449 |
@end{Legality} |
| 1450 |
|
| 1451 |
@begin{Notes} |
| 1452 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 1453 |
A @nt<library_item> mentioned in a @Chg{Version=[2], |
| 1454 |
New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]} of a compilation unit |
| 1455 |
is visible within the compilation unit and hence acts |
| 1456 |
just like an ordinary declaration. |
| 1457 |
Thus, within a compilation unit that mentions its declaration, the name of a |
| 1458 |
library package can be given in @nt{use_clause}s and can be used to |
| 1459 |
form expanded names, a library subprogram can be called, |
| 1460 |
and instances of a generic library unit can be declared. |
| 1461 |
If a child of a parent generic package is mentioned in a |
| 1462 |
@Chg{Version=[2], New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]}, |
| 1463 |
then the corresponding declaration nested within each visible instance |
| 1464 |
is visible within the compilation unit.@Chg{Version=[2], New=[ Similarly, |
| 1465 |
a @nt{library_item} mentioned in a |
| 1466 |
@nt{limited_with_clause} of a compilation unit is visible within the |
| 1467 |
compilation unit and thus can be used to form expanded names.],Old=[]} |
| 1468 |
|
| 1469 |
@begin{Ramification} |
| 1470 |
The rules given for @nt{with_clause}s are such that the same effect |
| 1471 |
is obtained whether the name of a library unit is mentioned once or |
| 1472 |
more than once by the applicable @nt{with_clause}s, or even within a |
| 1473 |
given @nt{with_clause}. |
| 1474 |
|
| 1475 |
If a @nt{with_clause} mentions a |
| 1476 |
@nt{library_@!unit_@!renaming_@!declaration}, |
| 1477 |
it only @lquotes@;mentions@rquotes@; the @nt<prefix>es appearing explicitly |
| 1478 |
in the @nt<with_clause> |
| 1479 |
(and the renamed view itself); |
| 1480 |
the @nt{with_clause} is not defined to mention the ancestors of the |
| 1481 |
renamed entity. |
| 1482 |
Thus, if X renames Y.Z, then @lquotes@;with X;@rquotes@; does not make the |
| 1483 |
declarations of Y or Z visible. |
| 1484 |
Note that this does not cause the dreaded visibility holes mentioned |
| 1485 |
above. |
| 1486 |
@end{Ramification} |
| 1487 |
@end{Notes} |
| 1488 |
|
| 1489 |
@begin{Examples} |
| 1490 |
|
| 1491 |
@begin{Example} |
| 1492 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 1493 |
@ChgAdded{Version=[2],Text=[@key(package) Office @key(is) |
| 1494 |
@key{end} Office;]} |
| 1495 |
|
| 1496 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 1497 |
@ChgAdded{Version=[2],Text=[@key(with) Ada.Strings.Unbounded; |
| 1498 |
@key(package) Office.Locations @key(is) |
| 1499 |
@key(type) Location @key(is new) Ada.Strings.Unbounded.Unbounded_String; |
| 1500 |
@key(end) Office.Locations;]} |
| 1501 |
|
| 1502 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 1503 |
@ChgAdded{Version=[2],Text=[@key(limited with) Office.Departments; --@RI[ types are incomplete] |
| 1504 |
@key(private with) Office.Locations; --@RI[ only visible in private part] |
| 1505 |
@key(package) Office.Employees @key(is) |
| 1506 |
@key(type) Employee @key(is private);]} |
| 1507 |
|
| 1508 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1509 |
@ChgAdded{Version=[2],Text=[ @key(function) Dept_Of(Emp : Employee) @key(return access) Departments.Department; |
| 1510 |
@key(procedure) Assign_Dept(Emp : @key(in out) Employee; |
| 1511 |
Dept : @key(access) Departments.Department);]} |
| 1512 |
|
| 1513 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1514 |
@ChgAdded{Version=[2],Text=[ ... |
| 1515 |
@key(private |
| 1516 |
type) Employee @key(is |
| 1517 |
record) |
| 1518 |
Dept : @key(access) Departments.Department; |
| 1519 |
Loc : Locations.Location; |
| 1520 |
... |
| 1521 |
@key(end record); |
| 1522 |
@key(end) Office.Employees;]} |
| 1523 |
|
| 1524 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1525 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]} |
| 1526 |
@ChgAdded{Version=[2],Text=[@key(limited with) Office.Employees; |
| 1527 |
@key(package) Office.Departments @key(is) |
| 1528 |
@key(type) Department @key(is) @Chg{Version=[5],New=[...],Old=[@key(private)]};]} |
| 1529 |
|
| 1530 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1531 |
@ChgAdded{Version=[2],Text=[ @key(function) Manager_Of(Dept : Department) @key(return access) Employees.Employee; |
| 1532 |
@key(procedure) Assign_Manager(Dept : @key(in out) Department; |
| 1533 |
Mgr : @key(access) Employees.Employee); |
| 1534 |
... |
| 1535 |
@key(end) Office.Departments;]} |
| 1536 |
@end{Example} |
| 1537 |
|
| 1538 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 1539 |
@ChgAdded{Version=[2],Text=[The @nt{limited_with_clause} may be used to support |
| 1540 |
mutually dependent abstractions that are split across multiple packages. In |
| 1541 |
this case, an employee is assigned to a department, and a department has a |
| 1542 |
manager who is an employee. If a @nt{with_clause} with the reserved word |
| 1543 |
@key(private) appears on one library unit and mentions a second library unit, |
| 1544 |
it provides visibility to the second library unit, but restricts that |
| 1545 |
visibility to the private part and body of the first unit. The compiler checks |
| 1546 |
that no use is made of the second unit in the visible part of the first unit.]} |
| 1547 |
|
| 1548 |
@end{Examples} |
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
@begin{Extend83} |
| 1553 |
@Defn{extensions to Ada 83} |
| 1554 |
The syntax rule for @nt{with_clause} is modified to allow expanded name |
| 1555 |
notation. |
| 1556 |
|
| 1557 |
A @nt<use_clause> in a @nt<context_clause> may be for |
| 1558 |
a package (or type) nested in a library package. |
| 1559 |
@end{Extend83} |
| 1560 |
|
| 1561 |
@begin{DiffWord83} |
| 1562 |
The syntax rule for @nt{context_clause} is modified to more closely reflect |
| 1563 |
the semantics. |
| 1564 |
The Ada 83 syntax rule implies that the @nt{use_clause}s that appear |
| 1565 |
immediately after a particular @nt{with_clause} are somehow attached to |
| 1566 |
that @nt{with_clause}, which is not true. |
| 1567 |
The new syntax allows a @nt{use_clause} to appear first, |
| 1568 |
but that is prevented by a textual rule that already exists in Ada 83. |
| 1569 |
|
| 1570 |
The concept of @lquotes@;scope of a @nt{with_clause}@rquotes@; (which is a region of text) |
| 1571 |
replaces RM83's notion of @lquotes@;apply to@rquotes@; |
| 1572 |
(a @nt{with_clause} applies to a @nt{library_item}) |
| 1573 |
The visibility rules are interested in a region of text, |
| 1574 |
not in a set of compilation units. |
| 1575 |
|
| 1576 |
No need to define @lquotes@;apply to@rquotes@; for @nt{use_clause}s. |
| 1577 |
Their semantics are fully covered by the @lquotes@;scope (of a @nt{use_clause})@rquotes@; |
| 1578 |
definition in @RefSecNum{Use Clauses}. |
| 1579 |
@end{DiffWord83} |
| 1580 |
|
| 1581 |
@begin{Incompatible95} |
| 1582 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00220-01]} |
| 1583 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 1584 |
@b[Amendment Correction:] A subprogram body acting as a declaration cannot |
| 1585 |
@key[with] a private child unit. This would allow public export of types |
| 1586 |
declared in private child packages, and thus cannot be allowed. This was |
| 1587 |
allowed by mistake in Ada 95; a subprogram that does this will now be |
| 1588 |
illegal.]} |
| 1589 |
@end{Incompatible95} |
| 1590 |
|
| 1591 |
@begin{Extend95} |
| 1592 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 1593 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1594 |
@nt{limited_with_clause}s are new. They make a limited view of a package |
| 1595 |
visible, where all of the types in the package are incomplete. They facilitate |
| 1596 |
construction of mutually recursive types in multiple packages.]} |
| 1597 |
|
| 1598 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]} |
| 1599 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]} |
| 1600 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1601 |
The syntax rules for @nt{with_clause} are modified to allow the reserved |
| 1602 |
word @key{private}. Private @nt{with_clause}s do not allow the use of their |
| 1603 |
@Chg{Version=[3],New=[@nt{library_item}],Old=[library item]} |
| 1604 |
in the visible part of their @nt{compilation_unit}. They also |
| 1605 |
allow using private units in more locations than in Ada 95.]} |
| 1606 |
@end{Extend95} |
| 1607 |
|
| 1608 |
@begin{Incompatible2005} |
| 1609 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0040-1]} |
| 1610 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:> |
| 1611 |
Added missing rule that |
| 1612 |
a limited with clause cannot name an ancestor unit. This is incompatible |
| 1613 |
if an Ada 2005 program does this, but as this is a new Ada 2005 feature and |
| 1614 |
the unintentionally allowed capability is not useful, the |
| 1615 |
incompatibility is very unlikely to occur in practice.]} |
| 1616 |
@end{Incompatible2005} |
| 1617 |
|
| 1618 |
@begin{DiffWord2005} |
| 1619 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0077-1]} |
| 1620 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Fixed wording so that |
| 1621 |
we are not checking whether something in a @nt{context_clause} |
| 1622 |
is @ldquote@;within the scope of@rdquote something, as @nt{context_clause}s |
| 1623 |
are never included in anything's scope. The intended meaning is unchanged, |
| 1624 |
however.]} |
| 1625 |
|
| 1626 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0122-1]} |
| 1627 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Fixed wording so the |
| 1628 |
rules for private with clauses also apply to "sprouted" generic child |
| 1629 |
units.]} |
| 1630 |
@end{DiffWord2005} |
| 1631 |
|
| 1632 |
|
| 1633 |
@begin{DiffWord2012} |
| 1634 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0261-1]} |
| 1635 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Fixed wording so the |
| 1636 |
privately withed units are visible in the subprogram specification of the |
| 1637 |
body of a private descendant; otherwise, the private specification is |
| 1638 |
legal but the completion is not.]} |
| 1639 |
@end{DiffWord2012} |
| 1640 |
|
| 1641 |
|
| 1642 |
@LabeledSubClause{Subunits of Compilation Units} |
| 1643 |
|
| 1644 |
@begin{Intro} |
| 1645 |
@redundant[Subunits are like child units, with these (important) differences: |
| 1646 |
subunits support the separate compilation of bodies |
| 1647 |
only (not declarations); |
| 1648 |
the parent contains a @nt{body_stub} |
| 1649 |
to indicate the existence and place of each of its subunits; |
| 1650 |
declarations appearing in the parent's body |
| 1651 |
can be visible within the subunits.] |
| 1652 |
@end{Intro} |
| 1653 |
|
| 1654 |
@begin{Syntax} |
| 1655 |
@Syn{lhs=<body_stub>,rhs="@Syn2{subprogram_body_stub} | @Syn2{package_body_stub} | @Syn2{task_body_stub} | @Syn2{protected_body_stub}"} |
| 1656 |
|
| 1657 |
|
| 1658 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 1659 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]} |
| 1660 |
@Syn{lhs=<subprogram_body_stub>,rhs="@Chg{Version=[2],New=< |
| 1661 |
[@Syn2{overriding_indicator}] |
| 1662 |
>,Old=[]}@Syn2{subprogram_specification} @key{is} @key{separate}@Chg{Version=[3],New=< |
| 1663 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 1664 |
|
| 1665 |
@begin{Discussion} |
| 1666 |
Although this syntax allows a @nt{parent_unit_name}, |
| 1667 |
that is disallowed by @RefSec{Compilation Units - Library Units}. |
| 1668 |
@end{Discussion} |
| 1669 |
|
| 1670 |
|
| 1671 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]} |
| 1672 |
@Syn{lhs=<package_body_stub>,rhs="@Chg{Version=[3],New=< |
| 1673 |
>,Old=[]}@key{package} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=< |
| 1674 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 1675 |
|
| 1676 |
|
| 1677 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]} |
| 1678 |
@Syn{lhs=<task_body_stub>,rhs="@Chg{Version=[3],New=< |
| 1679 |
>,Old=[]}@key{task} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=< |
| 1680 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 1681 |
|
| 1682 |
|
| 1683 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]} |
| 1684 |
@Syn{lhs=<protected_body_stub>,rhs="@Chg{Version=[3],New=< |
| 1685 |
>,Old=[]}@key{protected} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=< |
| 1686 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 1687 |
|
| 1688 |
|
| 1689 |
@Syn{lhs=<subunit>,rhs="@key{separate} (@Syn2{parent_unit_name}) @Syn2{proper_body}"} |
| 1690 |
@end{Syntax} |
| 1691 |
|
| 1692 |
@begin{Legality} |
| 1693 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00243-01]} |
| 1694 |
@Defn2{Term=[parent body], Sec=(of a subunit)} |
| 1695 |
The @i{parent body} of a subunit is the body of the program unit |
| 1696 |
denoted by its @nt{parent_unit_name}. |
| 1697 |
@Defn{subunit} The term @i{subunit} is used to refer to |
| 1698 |
a @nt{subunit} and also to the @nt{proper_body} of a @nt{subunit}. |
| 1699 |
@Chg{Version=[2],New=<The @i<subunits |
| 1700 |
of a program unit> include any subunit that |
| 1701 |
names that program unit as its parent, as well as any subunit that |
| 1702 |
names such a subunit as its parent (recursively).@Defn2{Term=[subunit], |
| 1703 |
Sec=(of a program unit)}>,Old=[]} |
| 1704 |
@begin{Reason} |
| 1705 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00243-01]} |
| 1706 |
@ChgAdded{Version=[2],Text=[We want any rule that applies to a subunit to apply |
| 1707 |
to a subunit of a subunit as well.]} |
| 1708 |
@end{Reason} |
| 1709 |
|
| 1710 |
@ChgToGlossary{Version=[5],Kind=[Added],Term=<Subunit>, |
| 1711 |
Text=<@ChgAdded{Version=[5],Text=[A body of a program unit that can be compiled |
| 1712 |
separately from its enclosing program unit.]}>} |
| 1713 |
|
| 1714 |
The parent body of a subunit shall be present in the current environment, |
| 1715 |
and shall contain a corresponding @nt{body_stub} |
| 1716 |
with the same @nt{defining_identifier} as the subunit. |
| 1717 |
@begin{Discussion} |
| 1718 |
This can't be a @ResolutionName, because a @nt{subunit} is not a |
| 1719 |
complete context. |
| 1720 |
@end{Discussion} |
| 1721 |
|
| 1722 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]} |
| 1723 |
A @nt{package_body_stub} shall be the completion of a |
| 1724 |
@nt{package_@!declaration} or @nt{generic_@!package_@!declaration}; |
| 1725 |
a @nt{task_@!body_@!stub} shall be the completion of a |
| 1726 |
@Chg{Version=[3],New=[task declaration],Old=[@ntf{task_@!declaration}]}; |
| 1727 |
a @nt{protected_@!body_stub} shall be the completion of a |
| 1728 |
@Chg{Version=[3],New=[protected declaration],Old=[@ntf{protected_@!declaration}]}. |
| 1729 |
|
| 1730 |
In contrast, |
| 1731 |
a @nt{subprogram_body_stub} need not be the completion of a previous |
| 1732 |
declaration, |
| 1733 |
@Redundant[in which case the @ntf{_stub} declares the subprogram]. |
| 1734 |
If the @ntf{_stub} is a completion, it shall be the completion of a |
| 1735 |
@nt{subprogram_declaration} or @nt{generic_subprogram_declaration}. |
| 1736 |
The profile of a @nt{subprogram_body_stub} that completes a declaration |
| 1737 |
shall conform fully to that of the declaration. |
| 1738 |
@Defn2{Term=[full conformance],Sec=(required)} |
| 1739 |
@begin{Discussion} |
| 1740 |
The part about @nt{subprogram_body_stub}s echoes the corresponding rule |
| 1741 |
for @ntf{subprogram_bodies} in @RefSec{Subprogram Bodies}. |
| 1742 |
@end{Discussion} |
| 1743 |
|
| 1744 |
A subunit that corresponds to a @nt{body_stub} shall be of |
| 1745 |
the same kind |
| 1746 |
(@ntf{package_}, @ntf{subprogram_}, @ntf{task_}, or @ntf{protected_}) |
| 1747 |
as the @nt{body_stub}. |
| 1748 |
The profile of a @nt{subprogram_body} |
| 1749 |
subunit shall be fully conformant to |
| 1750 |
that of the corresponding @nt{body_stub}. |
| 1751 |
@Defn2{Term=[full conformance],Sec=(required)} |
| 1752 |
|
| 1753 |
A @nt{body_stub} shall appear immediately within the |
| 1754 |
@nt{declarative_part} of a compilation unit body. |
| 1755 |
This rule does not apply within an instance of a generic unit. |
| 1756 |
@begin{Discussion} |
| 1757 |
@Defn{methodological restriction} |
| 1758 |
This is a methodological restriction; |
| 1759 |
that is, it is not necessary for the semantics of the language to |
| 1760 |
make sense. |
| 1761 |
@end{Discussion} |
| 1762 |
|
| 1763 |
The @nt{defining_identifier}s of all @nt{body_stub}s that appear |
| 1764 |
immediately within a particular @nt{declarative_part} shall be |
| 1765 |
distinct. |
| 1766 |
@end{Legality} |
| 1767 |
|
| 1768 |
@begin{LinkTime} |
| 1769 |
For each @nt{body_stub}, there shall be a subunit containing |
| 1770 |
the corresponding @nt{proper_body}. |
| 1771 |
@end{LinkTime} |
| 1772 |
|
| 1773 |
@begin{Notes} |
| 1774 |
@leading@;The rules in @RefSec{The Compilation Process} |
| 1775 |
say that a @nt{body_stub} is equivalent to the corresponding |
| 1776 |
@nt{proper_body}. This implies: |
| 1777 |
@begin{Itemize} |
| 1778 |
Visibility within a subunit is the |
| 1779 |
visibility that would be obtained at the place of the corresponding |
| 1780 |
@nt{body_stub} (within the parent body) if the |
| 1781 |
@nt{context_clause} of the subunit were appended to |
| 1782 |
that of the parent body. |
| 1783 |
@begin{Ramification} |
| 1784 |
Recursively. |
| 1785 |
Note that this transformation might make the parent illegal; |
| 1786 |
hence it is not a true equivalence, but applies only to visibility |
| 1787 |
within the subunit. |
| 1788 |
@end{Ramification} |
| 1789 |
|
| 1790 |
The effect of the elaboration of a @nt{body_stub} is to elaborate |
| 1791 |
the subunit. |
| 1792 |
@begin{Ramification} |
| 1793 |
The elaboration of a subunit is part of its parent body's elaboration, |
| 1794 |
whereas the elaboration of a child unit is not part of its parent |
| 1795 |
declaration's elaboration. |
| 1796 |
@end{Ramification} |
| 1797 |
@end{Itemize} |
| 1798 |
@begin{Ramification} |
| 1799 |
A @nt<library_item> that is mentioned in a @nt{with_clause} of a |
| 1800 |
subunit can be hidden (from direct @Chg{Version=[2],New=[visibility], |
| 1801 |
Old=[visiblity]}) by a declaration (with the same |
| 1802 |
@nt{identifier}) given in the subunit. |
| 1803 |
Moreover, such a @nt<library_item> can even be hidden by a declaration |
| 1804 |
given within the parent body since a library unit is declared in its |
| 1805 |
parent's declarative region; this however does not affect the |
| 1806 |
interpretation of the @nt{with_clause}s themselves, since only |
| 1807 |
@nt<library_item>s |
| 1808 |
are visible or directly visible |
| 1809 |
in @nt{with_clause}s. |
| 1810 |
|
| 1811 |
The body of a protected operation cannot be a subunit. |
| 1812 |
This follows from the syntax rules. |
| 1813 |
The body of a protected unit can be a subunit. |
| 1814 |
@end{Ramification} |
| 1815 |
@end{Notes} |
| 1816 |
|
| 1817 |
@begin{Examples} |
| 1818 |
@leading@keepnext@;The package Parent is first written without subunits: |
| 1819 |
@begin{Example} |
| 1820 |
@key[package] Parent @key[is] |
| 1821 |
@key[procedure] Inner; |
| 1822 |
@key[end] Parent; |
| 1823 |
|
| 1824 |
@key[with] Ada.Text_IO; |
| 1825 |
@key[package] @key[body] Parent @key[is] |
| 1826 |
Variable : String := "Hello, there."; |
| 1827 |
@key[procedure] Inner @key[is] |
| 1828 |
@key[begin] |
| 1829 |
Ada.Text_IO.Put_Line(Variable); |
| 1830 |
@key[end] Inner; |
| 1831 |
@key[end] Parent; |
| 1832 |
@end{Example} |
| 1833 |
|
| 1834 |
@begin{WideAbove} |
| 1835 |
@leading@;The body of procedure Inner may be turned into a subunit by rewriting |
| 1836 |
the package body as follows (with the declaration of Parent remaining |
| 1837 |
the same): |
| 1838 |
@end{WideAbove} |
| 1839 |
@begin{Example} |
| 1840 |
@key[package] @key[body] Parent @key[is] |
| 1841 |
Variable : String := "Hello, there."; |
| 1842 |
@key[procedure] Inner @key[is] @key[separate]; |
| 1843 |
@key[end] Parent; |
| 1844 |
|
| 1845 |
@key[with] Ada.Text_IO; |
| 1846 |
@key[separate](Parent) |
| 1847 |
@key[procedure] Inner @key[is] |
| 1848 |
@key[begin] |
| 1849 |
Ada.Text_IO.Put_Line(Variable); |
| 1850 |
@key[end] Inner; |
| 1851 |
@end{Example} |
| 1852 |
@end{Examples} |
| 1853 |
|
| 1854 |
@begin{Extend83} |
| 1855 |
@Defn{extensions to Ada 83} |
| 1856 |
Subunits of the same ancestor library unit are no longer restricted |
| 1857 |
to have distinct identifiers. |
| 1858 |
Instead, we require only that the full expanded names be distinct. |
| 1859 |
@end{Extend83} |
| 1860 |
|
| 1861 |
@begin{Extend95} |
| 1862 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 1863 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1864 |
An @nt{overriding_indicator} (see |
| 1865 |
@RefSecNum{Overriding Indicators}) is allowed on a subprogram stub.]} |
| 1866 |
@end{Extend95} |
| 1867 |
|
| 1868 |
@begin{DiffWord95} |
| 1869 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00243-01]} |
| 1870 |
@ChgAdded{Version=[2],Text=[Clarified that a subunit of a subunit is still a |
| 1871 |
subunit.]} |
| 1872 |
@end{DiffWord95} |
| 1873 |
|
| 1874 |
@begin{Extend2005} |
| 1875 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0267-1]} |
| 1876 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 1877 |
An optional @nt{aspect_specification} can be used in a |
| 1878 |
@nt{body_stub}. This is described in @RefSecNum{Aspect Specifications}.]} |
| 1879 |
@end{Extend2005} |
| 1880 |
|
| 1881 |
|
| 1882 |
@LabeledSubClause{The Compilation Process} |
| 1883 |
|
| 1884 |
@begin{Intro} |
| 1885 |
@Defn{environment} |
| 1886 |
@Defn{environment @nt<declarative_part>} |
| 1887 |
Each compilation unit submitted to the compiler is compiled in the |
| 1888 |
context of an @i{environment} @nt<declarative_part> (or simply, an |
| 1889 |
@i{environment}), |
| 1890 |
which is a conceptual @nt<declarative_part> that forms |
| 1891 |
the outermost declarative region of the |
| 1892 |
context of any @nt{compilation}. |
| 1893 |
At run time, an environment forms the @nt<declarative_part> of |
| 1894 |
the body of the environment task of a partition |
| 1895 |
(see @RefSec{Program Execution}). |
| 1896 |
@begin{Ramification} |
| 1897 |
At compile time, there is no particular construct that the |
| 1898 |
declarative region is considered to be nested within |
| 1899 |
@em the environment is the universe. |
| 1900 |
@end{Ramification} |
| 1901 |
@begin{Honest} |
| 1902 |
The environment is really just a portion of a @nt{declarative_part}, |
| 1903 |
since there might, for example, be bodies that do not yet exist. |
| 1904 |
@end{Honest} |
| 1905 |
|
| 1906 |
The @nt{declarative_item}s of the environment |
| 1907 |
are @nt{library_item}s appearing in an order |
| 1908 |
such that there are no forward semantic dependences. |
| 1909 |
Each included subunit |
| 1910 |
occurs in place of the corresponding stub. |
| 1911 |
The visibility rules apply as if the environment were the outermost |
| 1912 |
declarative region, |
| 1913 |
except that @nt{with_@!clause}s are needed to make |
| 1914 |
declarations of library units visible |
| 1915 |
(see @RefSecNum{Context Clauses - With Clauses}). |
| 1916 |
|
| 1917 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 1918 |
The mechanisms for creating an environment |
| 1919 |
and for adding and replacing compilation units within an environment |
| 1920 |
are implementation defined.@Chg{Version=[2],New=[ The mechanisms for adding a |
| 1921 |
compilation unit mentioned in a @nt{limited_with_clause} to an |
| 1922 |
environment are implementation defined.],Old=[]} |
| 1923 |
@ImplDef{The mechanisms for creating an environment |
| 1924 |
and for adding and replacing compilation units.} |
| 1925 |
@ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[The |
| 1926 |
mechanisms for adding a compilation unit mentioned in a @nt{limited_with_clause} |
| 1927 |
to an environment.],Old=[]}]} |
| 1928 |
@begin{Ramification} |
| 1929 |
The traditional model, used by most Ada 83 implementations, |
| 1930 |
is that one places a compilation unit in the environment |
| 1931 |
by compiling it. |
| 1932 |
Other models are possible. |
| 1933 |
For example, an implementation might define the environment to |
| 1934 |
be a directory; |
| 1935 |
that is, the compilation units in the environment are all the |
| 1936 |
compilation units in the source files contained in the directory. |
| 1937 |
In this model, the mechanism for replacing a compilation unit with a |
| 1938 |
new one is simply to edit the source file containing that compilation |
| 1939 |
unit. |
| 1940 |
@end{Ramification} |
| 1941 |
|
| 1942 |
@end{Intro} |
| 1943 |
|
| 1944 |
@begin{Resolution} |
| 1945 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0032],ARef=[AI95-00192-01]} |
| 1946 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]} |
| 1947 |
If a @nt<library_unit_body> that is a @nt<subprogram_body> is |
| 1948 |
submitted to the compiler, it is interpreted only as a completion |
| 1949 |
if a @nt<library_unit_declaration> @Chg{New=[], Old=[for a subprogram |
| 1950 |
or a generic subprogram ]}with the same @nt<defining_program_unit_name> |
| 1951 |
already exists in the environment @Chg{New=[for a subprogram other than |
| 1952 |
an instance of a generic subprogram or for a generic subprogram ], Old=[]} |
| 1953 |
(even if the profile of the body is not type conformant with that of the |
| 1954 |
declaration); otherwise@Chg{Version=[3],New=[,],Old=[]} the |
| 1955 |
@nt<subprogram_body> is |
| 1956 |
interpreted as both the declaration and body of a library subprogram. |
| 1957 |
@PDefn{type conformance} |
| 1958 |
@begin{Ramification} |
| 1959 |
The principle here is that a @nt{subprogram_body} should be |
| 1960 |
interpreted as only a completion if and only if it @lquotes@;might@rquotes@; |
| 1961 |
be legal as the completion of some preexisting declaration, |
| 1962 |
where @lquotes@;might@rquotes@; is defined in a way that does not require overload |
| 1963 |
resolution to determine. |
| 1964 |
|
| 1965 |
Hence, if the preexisting declaration is a @nt{subprogram_declaration} |
| 1966 |
or @nt{generic_subprogram_declaration}, we treat the new |
| 1967 |
@nt{subprogram_body} as its completion, because it @lquotes@;might@rquotes@; be legal. |
| 1968 |
If it turns out that the profiles don't fully conform, |
| 1969 |
it's an error. |
| 1970 |
In all other cases (the preexisting declaration is a |
| 1971 |
package or a generic package, |
| 1972 |
or an instance of a generic subprogram, |
| 1973 |
or a renaming, |
| 1974 |
or a @lquotes@;spec-less@rquotes@; subprogram, |
| 1975 |
or in the case where there is no preexisting thing), |
| 1976 |
the @nt{subprogram_body} declares a new subprogram. |
| 1977 |
|
| 1978 |
See also AI83-00266/09. |
| 1979 |
@end{Ramification} |
| 1980 |
@end{Resolution} |
| 1981 |
|
| 1982 |
@begin{Legality} |
| 1983 |
When a compilation unit is compiled, |
| 1984 |
all compilation units upon which it depends semantically |
| 1985 |
shall already exist in the environment; |
| 1986 |
@Defn2{Term=[consistency], Sec=(among compilation units)} |
| 1987 |
the set of these compilation units shall be @i{consistent} in the |
| 1988 |
sense that the new compilation unit shall not semantically depend |
| 1989 |
(directly or indirectly) on two different versions of the same compilation |
| 1990 |
unit, nor on an earlier version of itself. |
| 1991 |
@begin{Discussion} |
| 1992 |
For example, if package declarations A and B both say |
| 1993 |
@lquotes@;@key[with] X;@rquotes@;, and the user compiles a compilation unit that says |
| 1994 |
@lquotes@;@key[with] A, B;@rquotes@;, then the A and B have to be talking about the |
| 1995 |
same version of X. |
| 1996 |
@end{Discussion} |
| 1997 |
@begin{Ramification} |
| 1998 |
What it means to be a @lquotes@;different version@rquotes@; is not specified by the |
| 1999 |
language. In some implementations, it means that the compilation |
| 2000 |
unit has been recompiled. In others, it means that the |
| 2001 |
source of the compilation unit has been edited in some significant way. |
| 2002 |
|
| 2003 |
Note that an implementation cannot require the existence of |
| 2004 |
compilation units upon which the given one does not semantically |
| 2005 |
depend. |
| 2006 |
For example, an implementation is required to be able to compile a |
| 2007 |
compilation unit that says "@key{with} A;" when A's body does not |
| 2008 |
exist. |
| 2009 |
It has to be able to detect errors without looking at A's body. |
| 2010 |
|
| 2011 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2012 |
Similarly, the implementation has to be able to compile a call to a |
| 2013 |
subprogram for which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]} |
| 2014 |
Inline has been specified without |
| 2015 |
seeing the body of that subprogram @em inlining would not be |
| 2016 |
achieved in this case, but the call is still legal. |
| 2017 |
|
| 2018 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 2019 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]} |
| 2020 |
@ChgAdded{Version=[2],Text=[The @Chg{Version=[2],New=[consistency], |
| 2021 |
Old=[second]} rule applies to limited views as well |
| 2022 |
as the full view of a compilation unit. That means that an implementation needs |
| 2023 |
a way to enforce consistency of limited views, not just of full views.]} |
| 2024 |
@end{Ramification} |
| 2025 |
@end{Legality} |
| 2026 |
|
| 2027 |
@begin{ImplPerm} |
| 2028 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 2029 |
The implementation may require that a compilation unit be legal before |
| 2030 |
@Chg{Version=[2],New=[it can be mentioned in a @nt{limited_with_clause} or |
| 2031 |
it can be inserted],Old=[inserting it]} into the environment. |
| 2032 |
|
| 2033 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00214-01]} |
| 2034 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2035 |
When a compilation unit that declares or renames a library unit |
| 2036 |
is added to the environment, |
| 2037 |
the implementation may remove from the environment |
| 2038 |
any preexisting @nt<library_item> |
| 2039 |
@Chg{Version=[2],New=[or @nt<subunit> with the same full expanded name], |
| 2040 |
Old=[with the same @nt<defining_@!program_@!unit_name>]}. |
| 2041 |
When a compilation unit that is a subunit or the body |
| 2042 |
of a library unit is added to the environment, |
| 2043 |
the implementation may remove from the environment |
| 2044 |
any preexisting version of the same compilation unit. |
| 2045 |
@Chg{Version=[2],New=[When a compilation unit that |
| 2046 |
contains a @nt<body_stub> is added to the environment, the implementation may |
| 2047 |
remove any preexisting @nt<library_item> or @nt<subunit> with the same full |
| 2048 |
expanded name as the @nt<body_stub>.],Old=[]} |
| 2049 |
When a given compilation unit is removed from the environment, |
| 2050 |
the implementation may also remove any compilation unit that depends |
| 2051 |
semantically upon the given one. |
| 2052 |
If the given compilation unit contains the body of a subprogram @Chg{Version=[3],New=[for],Old=[to]} |
| 2053 |
which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]} Inline @Chg{Version=[3],New=[is True],Old=[applies]}, |
| 2054 |
the implementation may also remove any compilation unit containing a |
| 2055 |
call to that subprogram. |
| 2056 |
@begin{Ramification} |
| 2057 |
|
| 2058 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]} |
| 2059 |
The permissions given in this paragraph correspond to the traditional |
| 2060 |
model, where compilation units enter the environment by being |
| 2061 |
compiled into it, and the compiler checks their legality at that time. |
| 2062 |
@Chg{Version=[3],New=[An],Old=[A]} implementation model in which the |
| 2063 |
environment consists of all source files in a given directory might not |
| 2064 |
want to take advantage of these permissions. |
| 2065 |
Compilation units would not be checked for |
| 2066 |
legality as soon as they enter the environment; legality checking |
| 2067 |
would happen later, when compilation units are compiled. |
| 2068 |
In this model, compilation units might never be automatically removed |
| 2069 |
from the environment; |
| 2070 |
they would be removed when the user explicitly deletes a source file. |
| 2071 |
|
| 2072 |
Note that the rule is recursive: if the above permission is used to |
| 2073 |
remove a compilation unit containing an inlined subprogram call, |
| 2074 |
then compilation units that depend semantically upon the removed one |
| 2075 |
may also be removed, and so on. |
| 2076 |
|
| 2077 |
Note that here we are talking about dependences among existing |
| 2078 |
compilation units in the environment; |
| 2079 |
it doesn't matter what @nt{with_clause}s are attached to the new |
| 2080 |
compilation unit that triggered all this. |
| 2081 |
|
| 2082 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2083 |
An implementation may have other modes in which compilation units |
| 2084 |
in addition to the ones mentioned above are removed. |
| 2085 |
For example, an implementation might inline subprogram calls without |
| 2086 |
an explicit @Chg{Version=[3],New=[aspect],Old=[@nt{pragma}]} Inline. |
| 2087 |
If so, it either has to have a mode in which that optimization is |
| 2088 |
turned off, or it has to automatically regenerate code for the inlined |
| 2089 |
calls without requiring the user to resubmit them to the compiler. |
| 2090 |
@end{Ramification} |
| 2091 |
@begin{Discussion} |
| 2092 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0108],ARef=[AI95-00077-01]} |
| 2093 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]} |
| 2094 |
@ChgAdded{Version=[1],Text=[In the standard mode, implementations may only remove |
| 2095 |
units from the environment for one of the reasons listed here, or in response |
| 2096 |
to an explicit user command to modify the environment. It is not intended that |
| 2097 |
the act of compiling a unit is one of the |
| 2098 |
@lquotes@;@Chg{Version=[2],New=[mechanisms],Old=[mechansisms]}@rquotes for |
| 2099 |
removing units other than those specified by this International Standard.]} |
| 2100 |
|
| 2101 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00214-01]} |
| 2102 |
@ChgAdded{Version=[2],Text=[These rules are intended to ensure that an |
| 2103 |
implementation never need keep more than one compilation unit with any full |
| 2104 |
expanded name. In particular, it is not necessary to be able to have a subunit |
| 2105 |
and a child unit with the same name in the environment at one time.]} |
| 2106 |
|
| 2107 |
@end{Discussion} |
| 2108 |
@end{ImplPerm} |
| 2109 |
|
| 2110 |
@begin{Notes} |
| 2111 |
The rules of the language are enforced across |
| 2112 |
@nt{compilation} and compilation unit boundaries, |
| 2113 |
just as they are enforced within a single compilation unit. |
| 2114 |
@begin{Ramification} |
| 2115 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 2116 |
Note that @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{General} |
| 2117 |
requires an implementation to detect illegal compilation units at compile time. |
| 2118 |
@end{Ramification} |
| 2119 |
|
| 2120 |
@Defn{library} |
| 2121 |
An implementation may support a concept of a @i{library}, |
| 2122 |
which contains @nt{library_item}s. |
| 2123 |
If multiple libraries are supported, |
| 2124 |
the implementation has to define how a single environment is |
| 2125 |
constructed when a compilation unit is submitted to the compiler. |
| 2126 |
Naming conflicts between different libraries might be resolved by |
| 2127 |
treating each library as the root of a hierarchy of child library |
| 2128 |
units. |
| 2129 |
@IndexSee{Term=[program library],See=(library)} |
| 2130 |
@begin{ImplNote} |
| 2131 |
Alternatively, naming conflicts could be resolved via some sort of |
| 2132 |
hiding rule. |
| 2133 |
@end{ImplNote} |
| 2134 |
@begin{Discussion} |
| 2135 |
For example, the implementation might support a command to import |
| 2136 |
library Y into library X. |
| 2137 |
If a root library unit called LU (that is, Standard.LU) exists in Y, |
| 2138 |
then from the point of view of library X, |
| 2139 |
it could be called Y.LU. |
| 2140 |
X might contain library units that say, @lquotes@;@key[with] Y.LU;@rquotes@;. |
| 2141 |
@end{Discussion} |
| 2142 |
|
| 2143 |
A compilation unit containing an instantiation of a separately |
| 2144 |
compiled generic unit does not semantically depend on the body |
| 2145 |
of the generic unit. |
| 2146 |
Therefore, replacing the generic body in the environment |
| 2147 |
does not result in the removal of the compilation unit |
| 2148 |
containing the instantiation. |
| 2149 |
@begin{ImplNote} |
| 2150 |
Therefore, implementations have to be prepared to automatically |
| 2151 |
instantiate generic bodies at link-time, as needed. This might |
| 2152 |
imply a complete automatic recompilation, but it is the intent |
| 2153 |
of the language that generic bodies can be (re)instantiated without |
| 2154 |
forcing all of the compilation units that semantically depend |
| 2155 |
on the compilation unit containing the instantiation to be |
| 2156 |
recompiled. |
| 2157 |
@end{ImplNote} |
| 2158 |
@end{Notes} |
| 2159 |
|
| 2160 |
@begin{Extend83} |
| 2161 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00077-01],ARef=[AI95-00114-01]} |
| 2162 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 83} |
| 2163 |
Ada 83 allowed implementations to require that the body of a generic unit |
| 2164 |
be available when the instantiation is compiled; that permission is dropped |
| 2165 |
in Ada 95. This isn't really an extension (it doesn't allow Ada users to |
| 2166 |
write anything that they couldn't in Ada 83), but there isn't a more |
| 2167 |
appropriate category, and it does allow users more flexibility when |
| 2168 |
developing programs.]} |
| 2169 |
@end{Extend83} |
| 2170 |
|
| 2171 |
|
| 2172 |
@begin{DiffWord95} |
| 2173 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0032],ARef=[AI95-00192-01]} |
| 2174 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording was clarified to |
| 2175 |
ensure that a @nt{subprogram_body} is not considered a completion of |
| 2176 |
an instance of a generic subprogram.]} |
| 2177 |
|
| 2178 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00214-01]} |
| 2179 |
@ChgAdded{Version=[2],Text=[The permissions to remove a unit from the |
| 2180 |
environment were clarified to ensure that it is never necessary to keep |
| 2181 |
multiple (sub)units with the same full expanded name in the environment.]} |
| 2182 |
|
| 2183 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 2184 |
@ChgAdded{Version=[2],Text=[Units mentioned in a @nt{limited_with_clause} |
| 2185 |
were added to several rules; limited views have the same presence in the |
| 2186 |
environment as the corresponding full views.]} |
| 2187 |
@end{DiffWord95} |
| 2188 |
|
| 2189 |
@LabeledSubClause{Pragmas and Program Units} |
| 2190 |
|
| 2191 |
@begin{Intro} |
| 2192 |
@Redundant[This subclause discusses pragmas related to program units, |
| 2193 |
library units, and @nt{compilation}s.] |
| 2194 |
@end{Intro} |
| 2195 |
|
| 2196 |
@begin{Resolution} |
| 2197 |
@RootDefn{program unit pragma} |
| 2198 |
@RootDefn{pragma, program unit} |
| 2199 |
Certain @nt{pragma}s are defined to be @i{program unit pragmas}. |
| 2200 |
@PDefn2{Term=[apply], Sec=(to a program unit by a program unit pragma)} |
| 2201 |
A @nt{name} given as the argument of a program unit pragma shall resolve to |
| 2202 |
denote the declarations or renamings of one or more program |
| 2203 |
units that occur immediately within the declarative region or @nt<compilation> |
| 2204 |
in which the @nt<pragma> immediately occurs, or it shall resolve to denote |
| 2205 |
the declaration of the immediately enclosing program unit (if any); |
| 2206 |
the @nt{pragma} applies to the denoted program |
| 2207 |
unit(s). |
| 2208 |
If there are no @nt{name}s given as arguments, |
| 2209 |
the @nt{pragma} applies to the immediately |
| 2210 |
enclosing program unit. |
| 2211 |
@begin{Ramification} |
| 2212 |
The fact that this is a @ResolutionName means that the @nt{pragma} |
| 2213 |
will not apply to declarations from outer declarative regions. |
| 2214 |
@end{Ramification} |
| 2215 |
|
| 2216 |
@end{Resolution} |
| 2217 |
|
| 2218 |
@begin{Legality} |
| 2219 |
@leading@keepnext@;A program unit pragma shall appear in one of these places: |
| 2220 |
@begin{Itemize} |
| 2221 |
At the place of a @nt{compilation_unit}, |
| 2222 |
in which case the @nt<pragma> |
| 2223 |
shall immediately follow in the same @nt<compilation> (except for |
| 2224 |
other @nt{pragma}s) |
| 2225 |
a @nt{library_@!unit_@!declaration} that is a @nt<subprogram_@!declaration>, |
| 2226 |
@nt<generic_@!subprogram_@!declaration>, or @nt<generic_@!instantiation>, and |
| 2227 |
the @nt<pragma> shall have an argument that is a @nt<name> denoting |
| 2228 |
that declaration. |
| 2229 |
@begin{Ramification} |
| 2230 |
The @nt{name} has to denote the immediately preceding |
| 2231 |
@nt{library_unit_declaration}. |
| 2232 |
@end{Ramification} |
| 2233 |
|
| 2234 |
@ChgRef{Version=[1], Kind=[Revised], Ref=[8652/0033], ARef=[AI95-00136-01]} |
| 2235 |
Immediately within the @Chg{New=[visible part],Old=[declaration]} of a |
| 2236 |
program unit and before any nested declaration@Chg{New=[ (but not within a |
| 2237 |
generic formal part)], Old=[]}, in which case the argument, |
| 2238 |
if any, shall be a @nt{direct_name} |
| 2239 |
that denotes the immediately enclosing program unit declaration. |
| 2240 |
@begin{Ramification} |
| 2241 |
The argument is optional in this case. |
| 2242 |
@end{Ramification} |
| 2243 |
|
| 2244 |
At the place of a declaration |
| 2245 |
other than the first, |
| 2246 |
of a @nt{declarative_part} or program unit declaration, |
| 2247 |
in which case the @nt{pragma} shall have an argument, |
| 2248 |
which shall be a @nt{direct_name} |
| 2249 |
that denotes one or more of the following (and nothing else): |
| 2250 |
a @nt{subprogram_@!declaration}, a @nt{generic_@!subprogram_@!declaration}, |
| 2251 |
or a @nt{generic_@!instantiation}, of the same @nt<declarative_@!part> or |
| 2252 |
program unit declaration. |
| 2253 |
@begin{Ramification} |
| 2254 |
If you want to denote a @nt<subprogram_body> that is not a |
| 2255 |
completion, or a |
| 2256 |
@nt{package_declaration}, for example, you have to put the @nt{pragma} |
| 2257 |
inside. |
| 2258 |
@end{Ramification} |
| 2259 |
@end{Itemize} |
| 2260 |
|
| 2261 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0132-1]} |
| 2262 |
@RootDefn{library unit pragma} |
| 2263 |
@RootDefn{pragma, library unit} |
| 2264 |
@PDefn2{Term=[program unit pragma], Sec=(library unit pragmas)} |
| 2265 |
@PDefn2{Term=[pragma, program unit], Sec=(library unit pragmas)} |
| 2266 |
Certain program unit pragmas are defined to be |
| 2267 |
@i{library unit pragmas}. |
| 2268 |
@Chg{Version=[3],New=[If a library unit pragma applies to a program unit, |
| 2269 |
the program unit shall be],Old=[The @nt{name}, if |
| 2270 |
any, in a library unit pragma shall denote the declaration of]} a library unit. |
| 2271 |
@begin{Ramification} |
| 2272 |
This, together with the rules for program unit pragmas above, |
| 2273 |
implies that if a library unit pragma applies to a @nt{subprogram_declaration} |
| 2274 |
(and similar things), it has to appear immediately after the |
| 2275 |
@nt{compilation_unit}, whereas if the @nt{pragma} applies to a |
| 2276 |
@nt{package_declaration}, a @nt{subprogram_body} that is not a |
| 2277 |
completion (and similar things), it has to appear inside, as the first |
| 2278 |
@nt{declarative_item}. |
| 2279 |
@end{Ramification} |
| 2280 |
@end{Legality} |
| 2281 |
|
| 2282 |
@begin{StaticSem} |
| 2283 |
@ChgRef{Version=[1], Kind=[Added], Ref=[8652/0034], ARef=[AI95-00041-01]} |
| 2284 |
@ChgAdded{Version=[1],Text=[A library unit pragma that applies to a generic |
| 2285 |
unit does not apply to its instances, unless a specific rule for the pragma |
| 2286 |
specifies the contrary.]} |
| 2287 |
@end{StaticSem} |
| 2288 |
|
| 2289 |
@begin{LinkTime} |
| 2290 |
@RootDefn{configuration pragma} |
| 2291 |
@RootDefn{pragma, configuration} |
| 2292 |
Certain @nt{pragma}s are defined to be @i{configuration pragmas}; |
| 2293 |
they shall appear before the first @nt{compilation_unit} |
| 2294 |
of a @nt{compilation}. |
| 2295 |
@Redundant[They are generally used to select a partition-wide |
| 2296 |
or system-wide option.] |
| 2297 |
The @nt<pragma> applies to all @nt{compilation_unit}s |
| 2298 |
appearing in the @nt{compilation}, |
| 2299 |
unless there are none, in which case it applies to all future |
| 2300 |
@nt{compilation_unit}s compiled into the same environment. |
| 2301 |
@end{LinkTime} |
| 2302 |
|
| 2303 |
@begin{ImplPerm} |
| 2304 |
@ChgRef{Version=[2], Kind=[Revised], ARef=[AI95-00212-01]} |
| 2305 |
An implementation may @Chg{Version=[2], New=[require that configuration |
| 2306 |
pragmas that select partition-wide or system-wide options be compiled], |
| 2307 |
Old=[place restrictions on |
| 2308 |
configuration pragmas, so long as it allows them]} when the environment |
| 2309 |
contains no @nt{library_item}s other than those of the predefined environment. |
| 2310 |
@Chg{Version=[2], New=[In this case, the implementation shall still accept |
| 2311 |
configuration pragmas in individual compilations that confirm the initially |
| 2312 |
selected partition-wide or system-wide options.],Old=[]} |
| 2313 |
|
| 2314 |
@end{ImplPerm} |
| 2315 |
|
| 2316 |
@begin{ImplAdvice} |
| 2317 |
@ChgRef{Version=[1], Kind=[AddedNormal], Ref=[8652/0034], ARef=[AI95-00041-01]} |
| 2318 |
@ChgAdded{Version=[1],Text=[When applied to a generic unit, a program unit pragma that |
| 2319 |
is not a library unit pragma should apply to each instance of the generic unit |
| 2320 |
for which there is not an overriding pragma applied directly to the instance.]} |
| 2321 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2322 |
Text=[When applied to a generic unit, a program unit pragma that |
| 2323 |
is not a library unit pragma should apply to each instance of the generic unit |
| 2324 |
for which there is not an overriding pragma applied directly to the instance.]}]} |
| 2325 |
@end{ImplAdvice} |
| 2326 |
|
| 2327 |
|
| 2328 |
@begin{DiffWord95} |
| 2329 |
@ChgRef{Version=[2], Kind=[AddedNormal], Ref=[8652/0033], ARef=[AI95-00136-01]} |
| 2330 |
@ChgAdded{Version=[2], Text=[@B<Corrigendum:> The wording was corrected to |
| 2331 |
ensure that a program unit pragma cannot appear in private parts or |
| 2332 |
generic formal parts.]} |
| 2333 |
|
| 2334 |
@ChgRef{Version=[2], Kind=[AddedNormal], Ref=[8652/0034], |
| 2335 |
ARef=[AI95-00041-01]} @ChgAdded{Version=[2], Text=[@B<Corrigendum:> The |
| 2336 |
wording was clarified to explain the meaning of program unit and library unit |
| 2337 |
pragmas in generic units.]} |
| 2338 |
|
| 2339 |
@ChgRef{Version=[2], Kind=[AddedNormal]} |
| 2340 |
@ChgAdded{Version=[2], Text=[The Implementation Advice added by the |
| 2341 |
Corrigendum was moved, as it was not in the normal order. (This changes the |
| 2342 |
paragraph number.) It originally was directly after the new Static Semantics |
| 2343 |
rule.]} |
| 2344 |
|
| 2345 |
@ChgRef{Version=[2], Kind=[AddedNormal], ARef=[AI95-00212-01]} |
| 2346 |
@ChgAdded{Version=[2], Type=[Leading],Keepnext=[T],Text=[The permission to |
| 2347 |
place restrictions was clarified to:]} |
| 2348 |
@begin{itemize} |
| 2349 |
@ChgRef{Version=[2], Kind=[AddedNormal]} |
| 2350 |
@ChgAdded{Version=[2], Text=[Ensure that it applies only to partition-wide |
| 2351 |
configuration pragmas, not ones like Assertion_Policy (see |
| 2352 |
@RefSecNum{Pragmas Assert and Assertion_Policy}), which can be different |
| 2353 |
in different units; and]} |
| 2354 |
|
| 2355 |
@ChgRef{Version=[2], Kind=[AddedNormal]} |
| 2356 |
@ChgAdded{Version=[2], Text=[Ensure that confirming pragmas are always allowed.]} |
| 2357 |
@end{itemize} |
| 2358 |
@end{DiffWord95} |
| 2359 |
|
| 2360 |
@begin{DiffWord2005} |
| 2361 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0132-1]} |
| 2362 |
@ChgAdded{Version=[3], Text=[@b<Correction:> A library unit pragma must |
| 2363 |
apply directly to a library unit, even if no name is given in the pragma.]} |
| 2364 |
@end{DiffWord2005} |
| 2365 |
|
| 2366 |
|
| 2367 |
@LabeledSubClause{Environment-Level Visibility Rules} |
| 2368 |
|
| 2369 |
@begin{Intro} |
| 2370 |
@Redundant[The normal visibility rules do not apply within a |
| 2371 |
@nt{parent_unit_name} or a @nt{context_clause}, |
| 2372 |
nor within a @nt{pragma} that appears at the place of a compilation unit. |
| 2373 |
The special visibility rules for those contexts |
| 2374 |
are given here.] |
| 2375 |
@end{Intro} |
| 2376 |
|
| 2377 |
@begin{StaticSem} |
| 2378 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00312-01]} |
| 2379 |
@PDefn2{Term=[directly visible], Sec=(within the |
| 2380 |
@nt{parent_unit_name} of a library unit)} |
| 2381 |
@PDefn2{Term=[visible], Sec=(within the |
| 2382 |
@nt{parent_unit_name} of a library unit)} |
| 2383 |
@PDefn2{Term=[directly visible], Sec=(within a @nt{with_clause})} |
| 2384 |
@PDefn2{Term=[visible], Sec=(within a @nt{with_clause})} |
| 2385 |
Within the @nt{parent_unit_name} at the beginning of |
| 2386 |
@Chg{Version=[2],New=[an explicit],Old=[a]} @nt{library_item}, |
| 2387 |
and within a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}], |
| 2388 |
Old=[@nt{with_clause}]}, the only declarations |
| 2389 |
that are visible are those that are@Chg{Version=[2],New=[ explicit],Old=[]} |
| 2390 |
@nt<library_item>s of the environment, |
| 2391 |
and the only declarations that are directly visible are those that |
| 2392 |
are@Chg{Version=[2],New=[ explicit],Old=[]} root @nt<library_item>s |
| 2393 |
of the environment. |
| 2394 |
@Chg{Version=[2],New=[Within a @nt{limited_with_clause}, the only declarations |
| 2395 |
that are visible are those that are the implicit declaration of the |
| 2396 |
limited view of a library package of the environment, and the only |
| 2397 |
declarations that are directly visible are those that are the |
| 2398 |
implicit declaration of the limited view of a root library package.], |
| 2399 |
Old=[@Defn{notwithstanding} |
| 2400 |
Notwithstanding the rules of @RefSecNum(Selected Components), |
| 2401 |
an expanded name in a @nt{with_clause} may consist of a |
| 2402 |
@nt<prefix> that denotes a generic package and a @nt<selector_name> that |
| 2403 |
denotes a child of that generic package. |
| 2404 |
@Redundant[(The child is necessarily a generic unit; |
| 2405 |
see @RefSecNum{Compilation Units - Library Units}.)]]} |
| 2406 |
|
| 2407 |
@begin{Ramification} |
| 2408 |
In @lquotes@;@key{package} P.Q.R @key{is} ... @key{end} P.Q.R;@rquotes@;, |
| 2409 |
this rule requires P to be a root library unit, |
| 2410 |
and Q to be a library unit |
| 2411 |
(because those are the things that are directly visible and visible). |
| 2412 |
Note that visibility does not apply between the @lquotes@;@key{end}@rquotes@; |
| 2413 |
and the @lquotes@;;@rquotes@;. |
| 2414 |
|
| 2415 |
Physically nested declarations are not visible at these places. |
| 2416 |
|
| 2417 |
@ChgNote{Changed the classification of this note from Reason to Ramification, |
| 2418 |
as it certainly isn't a "reason". Besides, there were two reasons, which was |
| 2419 |
goofy.} |
| 2420 |
Although Standard is visible at these places, |
| 2421 |
it is impossible to name it, |
| 2422 |
since it is not directly visible, |
| 2423 |
and it has no parent. |
| 2424 |
|
| 2425 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 2426 |
@ChgAdded{Version=[2],Text=[Only compilation units defining limited views |
| 2427 |
can be mentioned in a @nt{limited_with_clause}, while only compilation |
| 2428 |
units defining full views (that is, the explicit declarations) can be mentioned |
| 2429 |
in a @nt{nonlimited_with_clause}. This resolves the conflict inherent in having |
| 2430 |
two compilation units with the same defining name.]} |
| 2431 |
@end{Ramification} |
| 2432 |
@begin{Reason} |
| 2433 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00312-01]} |
| 2434 |
@ChgDeleted{Version=[2],Text=[The @lquotes@;notwithstanding@rquotes@; part |
| 2435 |
allows @lquotes@;@key[with] A.B;@rquotes@; |
| 2436 |
where A is a generic library package and B is one of its |
| 2437 |
(generic) children. |
| 2438 |
This is necessary because it is not normally legal to use an expanded |
| 2439 |
name to reach inside a generic package.]} |
| 2440 |
@end{Reason} |
| 2441 |
|
| 2442 |
@PDefn2{Term=[directly visible], Sec=(within a @nt{use_clause} in a @nt{context_clause})} |
| 2443 |
@PDefn2{Term=[visible], Sec=(within a @nt{use_clause} in a @nt{context_clause})} |
| 2444 |
@PDefn2{Term=[directly visible], Sec=(within a @nt{pragma} in a @nt{context_clause})} |
| 2445 |
@PDefn2{Term=[visible], Sec=(within a @nt{pragma} in a @nt{context_clause})} |
| 2446 |
Within a @nt{use_clause} or @nt{pragma} |
| 2447 |
that is within a @nt{context_clause}, |
| 2448 |
each @nt<library_item> mentioned in a previous |
| 2449 |
@nt{with_clause} of the same @nt{context_clause} is visible, |
| 2450 |
and each root @nt<library_item> so mentioned is directly visible. |
| 2451 |
In addition, |
| 2452 |
within such a @nt{use_clause}, |
| 2453 |
if a given declaration is visible or directly |
| 2454 |
visible, |
| 2455 |
each declaration that occurs immediately within the given declaration's |
| 2456 |
visible part is also visible. |
| 2457 |
No other declarations are visible or directly visible. |
| 2458 |
@begin{Discussion} |
| 2459 |
Note the word @lquotes@;same@rquotes@;. |
| 2460 |
For example, if a @nt{with_clause} on a declaration mentions X, |
| 2461 |
this does not make X visible in @nt{use_clause}s and @nt{pragma}s |
| 2462 |
that are on the body. |
| 2463 |
The reason for this rule is |
| 2464 |
the one-pass @nt{context_clause}s @MetaRulesName. |
| 2465 |
|
| 2466 |
Note that the second part of the rule does not |
| 2467 |
mention @nt{pragma}s. |
| 2468 |
@end{Discussion} |
| 2469 |
|
| 2470 |
@PDefn2{Term=[directly visible], Sec=(within the |
| 2471 |
@nt{parent_unit_name} of a subunit)} |
| 2472 |
@PDefn2{Term=[visible], Sec=(within the |
| 2473 |
@nt{parent_unit_name} of a subunit)} |
| 2474 |
Within the @nt{parent_unit_name} of a subunit, @nt<library_item>s |
| 2475 |
are visible as they are in |
| 2476 |
the @nt{parent_unit_name} of a @nt{library_item}; |
| 2477 |
in addition, the declaration corresponding to each |
| 2478 |
@nt{body_stub} in the environment |
| 2479 |
is also visible. |
| 2480 |
@begin{Ramification} |
| 2481 |
For a subprogram without a separate @nt<subprogram_declaration>, |
| 2482 |
the @nt<body_stub> itself is the declaration. |
| 2483 |
@end{Ramification} |
| 2484 |
|
| 2485 |
@PDefn2{Term=[directly visible], Sec=(within a @nt{pragma} |
| 2486 |
that appears at the place of a compilation unit)} |
| 2487 |
@PDefn2{Term=[visible], Sec=(within a @nt{pragma} |
| 2488 |
that appears at the place of a compilation unit)} |
| 2489 |
Within a @nt{pragma} that appears at the place of a compilation unit, |
| 2490 |
the immediately preceding @nt<library_item> and each of its |
| 2491 |
ancestors is visible. |
| 2492 |
The ancestor root @nt<library_item> is directly visible. |
| 2493 |
|
| 2494 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00312-01]} |
| 2495 |
@ChgAdded{Version=[2],Text=[@Defn{notwithstanding} |
| 2496 |
Notwithstanding the rules of @RefSecNum(Selected Components), |
| 2497 |
an expanded name in a @nt{with_clause}, a @nt{pragma} in a @nt{context_clause}, |
| 2498 |
or a @nt{pragma} that appears at the place of a compilation unit |
| 2499 |
may consist of a @nt{prefix} that denotes a generic package and |
| 2500 |
a @nt<selector_name> that denotes a child of that generic package. |
| 2501 |
@Redundant[(The child is necessarily a generic unit; |
| 2502 |
see @RefSecNum{Compilation Units - Library Units}.)]]} |
| 2503 |
@begin{Reason} |
| 2504 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2505 |
@ChgAdded{Version=[2],Text=[This rule allows @key[with] A.B; and |
| 2506 |
@key[pragma] Elaborate(A.B); where A is a |
| 2507 |
generic library package and B is one of its (generic) children. This is |
| 2508 |
necessary because it is not normally legal to use an expanded |
| 2509 |
name to reach inside a generic package.]} |
| 2510 |
@end{Reason} |
| 2511 |
|
| 2512 |
@end{StaticSem} |
| 2513 |
|
| 2514 |
@begin{DiffWord83} |
| 2515 |
The special visibility rules that apply within a |
| 2516 |
@nt{parent_unit_name} or a @nt{context_clause}, |
| 2517 |
and within a @nt{pragma} that appears at the place of a |
| 2518 |
@nt{compilation_unit} are clarified. |
| 2519 |
|
| 2520 |
Note that a @nt{context_clause} is not part of any declarative region. |
| 2521 |
|
| 2522 |
We considered making the visibility rules within |
| 2523 |
@nt{parent_unit_name}s and @nt{context_clause}s follow from the |
| 2524 |
context of compilation. |
| 2525 |
However, this attempt failed for various reasons. |
| 2526 |
For example, it would require @nt{use_clause}s in |
| 2527 |
@nt{context_clause}s to be within the declarative region of Standard, |
| 2528 |
which sounds suspiciously like a kludge. |
| 2529 |
And we would still need a special rule to prevent seeing things |
| 2530 |
(in our own @nt{context_clause}) |
| 2531 |
that were with-ed by our parent, etc. |
| 2532 |
@end{DiffWord83} |
| 2533 |
|
| 2534 |
@begin{DiffWord95} |
| 2535 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 2536 |
@ChgAdded{Version=[2],Text=[Added separate visibility rules for |
| 2537 |
@nt{limited_with_clause}s; the existing rules apply only to |
| 2538 |
@nt{nonlimited_with_clause}s.]} |
| 2539 |
|
| 2540 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00312-01]} |
| 2541 |
@ChgAdded{Version=[2],Text=[Clarified that the name of a generic child unit |
| 2542 |
may appear in a @nt{pragma} in a @nt{context_clause}.]} |
| 2543 |
@end{DiffWord95} |
| 2544 |
|
| 2545 |
|
| 2546 |
@LabeledClause{Program Execution} |
| 2547 |
|
| 2548 |
@begin{Intro} |
| 2549 |
@Defn{program} |
| 2550 |
@Defn{program execution} |
| 2551 |
@IndexSee{Term=[running a program],See=(program execution)} |
| 2552 |
An Ada @i{program} consists |
| 2553 |
of a set of @i{partitions}@Redundant[, |
| 2554 |
which can execute in parallel with one another, |
| 2555 |
possibly in a separate address space, |
| 2556 |
and possibly on a separate computer.] |
| 2557 |
@end{Intro} |
| 2558 |
|
| 2559 |
@begin{LinkTime} |
| 2560 |
|
| 2561 |
@RootDefn{partition} |
| 2562 |
@Defn{partition building} |
| 2563 |
A partition is a program or part of a program |
| 2564 |
that can be invoked from outside |
| 2565 |
the Ada implementation. |
| 2566 |
@Redundant[For example, on many systems, |
| 2567 |
a partition might be an executable file |
| 2568 |
generated by the system linker.] |
| 2569 |
@Defn{explicitly assign} |
| 2570 |
The user can @i{explicitly assign} library units to a partition. |
| 2571 |
The assignment is done in an implementation-defined manner. |
| 2572 |
The compilation units included in a partition are |
| 2573 |
those of the explicitly assigned library units, |
| 2574 |
as well as other compilation units @i{needed by} those library units. |
| 2575 |
The compilation units needed by a given compilation unit are determined |
| 2576 |
as follows |
| 2577 |
(unless specified otherwise via an implementation-defined @nt{pragma}, |
| 2578 |
or by some other implementation-defined means): |
| 2579 |
@IndexSee{Term=[linking],See=(partition building)} |
| 2580 |
@RootDefn2{Term=[compilation units needed], Sec=(by a compilation unit)} |
| 2581 |
@RootDefn2{Term=[needed], Sec=(of a compilation unit by another)} |
| 2582 |
@begin{Discussion} |
| 2583 |
From a run-time point of view, |
| 2584 |
an Ada 95 partition is identical to an Ada 83 program |
| 2585 |
@em implementations were always allowed to provide inter-program |
| 2586 |
communication mechanisms. |
| 2587 |
The additional semantics of partitions is that interfaces between |
| 2588 |
them can be defined to obey normal language rules |
| 2589 |
(as is done in @RefSec{Distributed Systems}), |
| 2590 |
whereas interfaces between separate programs had no particular |
| 2591 |
semantics. |
| 2592 |
@end{Discussion} |
| 2593 |
@ImplDef{The manner of explicitly assigning library units to a partition.} |
| 2594 |
@ImplDef{The implementation-defined means, if any, of specifying which |
| 2595 |
compilation units are needed by a given compilation unit.} |
| 2596 |
@begin{Discussion} |
| 2597 |
There are no pragmas that @lquotes@;specify otherwise@rquotes@; defined by the |
| 2598 |
core language. However, an implementation is allowed to provide such |
| 2599 |
pragmas, and in fact @RefSec{Distributed Systems} defines some |
| 2600 |
pragmas whose semantics includes reducing the set of |
| 2601 |
compilation units described here. |
| 2602 |
@end{Discussion} |
| 2603 |
@begin{Itemize} |
| 2604 |
A compilation unit needs itself; |
| 2605 |
|
| 2606 |
If a compilation unit is needed, then so are any compilation units |
| 2607 |
upon which it depends semantically; |
| 2608 |
|
| 2609 |
If a @nt{library_unit_declaration} is needed, |
| 2610 |
then so is any corresponding |
| 2611 |
@nt{library_unit_body}; |
| 2612 |
|
| 2613 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]} |
| 2614 |
If a compilation unit with stubs is needed, |
| 2615 |
then so are any corresponding subunits@Chg{Version=[2],New=[;],Old=[.]} |
| 2616 |
|
| 2617 |
@begin{Discussion} |
| 2618 |
Note that in the environment, the stubs are replaced with the |
| 2619 |
corresponding @ntf{proper_bodies}. |
| 2620 |
@end{Discussion} |
| 2621 |
|
| 2622 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 2623 |
@ChgAdded{Version=[2],Text=[If the (implicit) declaration of the limited view |
| 2624 |
of a library package is needed, then so is the explicit declaration of the |
| 2625 |
library package.]} |
| 2626 |
|
| 2627 |
@end{Itemize} |
| 2628 |
@begin{Discussion} |
| 2629 |
Note that a child unit is not included |
| 2630 |
just because its parent is included @em to include a child, |
| 2631 |
mention it in a @nt{with_clause}. |
| 2632 |
|
| 2633 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 2634 |
@ChgAdded{Version=[2],Text=[A package is included in a partition even if the |
| 2635 |
only reference to it is in a @nt{limited_with_clause}. While this isn't |
| 2636 |
strictly necessary (no objects of types imported from such a unit can be |
| 2637 |
created), it ensures that all incomplete types are eventually completed, and |
| 2638 |
is the least surprising option.]} |
| 2639 |
@end{Discussion} |
| 2640 |
|
| 2641 |
@Defn2{Term=[main subprogram], Sec=(for a partition)} |
| 2642 |
The user can optionally designate |
| 2643 |
(in an implementation-defined manner) |
| 2644 |
one subprogram as the @i{main subprogram} for the partition. |
| 2645 |
A main subprogram, if specified, shall be a subprogram. |
| 2646 |
@begin{Discussion} |
| 2647 |
This may seem superfluous, |
| 2648 |
since it follows from the definition. |
| 2649 |
But we would like to have every error message that might be generated |
| 2650 |
(before run time) by an implementation correspond to some |
| 2651 |
explicitly stated @lquotes@;shall@rquotes@; rule. |
| 2652 |
|
| 2653 |
Of course, this does not mean that the @lquotes@;shall@rquotes@; rules correspond |
| 2654 |
one-to-one with an implementation's error messages. For example, |
| 2655 |
the rule that says overload resolution @lquotes@;shall@rquotes@; succeed in producing a |
| 2656 |
single interpretation would correspond to many error messages in a good |
| 2657 |
implementation @em the implementation would want to explain to the user |
| 2658 |
exactly why overload resolution failed. |
| 2659 |
This is especially true for the syntax rules @em they are considered |
| 2660 |
part of overload resolution, but in most cases, one would expect an |
| 2661 |
error message based on the particular syntax rule that was violated. |
| 2662 |
@end{Discussion} |
| 2663 |
@ImplDef{The manner of designating the main subprogram of a partition.} |
| 2664 |
@begin{Ramification} |
| 2665 |
An implementation cannot require the user to specify, say, all of the |
| 2666 |
library units to be included. |
| 2667 |
It has to support, for example, perhaps the most typical case, |
| 2668 |
where the user specifies just one library unit, |
| 2669 |
the main program. |
| 2670 |
The implementation has to do the work of tracking down all the other ones. |
| 2671 |
@end{Ramification} |
| 2672 |
|
| 2673 |
@Defn{environment task} |
| 2674 |
Each partition has an anonymous @i{environment task}@Redundant[, |
| 2675 |
which is an implicit outermost task whose execution |
| 2676 |
elaborates the @nt{library_item}s of the environment |
| 2677 |
@nt{declarative_part}, and then calls the main subprogram, |
| 2678 |
if there is one. |
| 2679 |
A partition's execution is that of its tasks.] |
| 2680 |
@begin{Ramification} |
| 2681 |
An environment task has no master; |
| 2682 |
all nonenvironment tasks have masters. |
| 2683 |
|
| 2684 |
An implementation is allowed to support |
| 2685 |
multiple concurrent executions of the same partition. |
| 2686 |
@end{Ramification} |
| 2687 |
|
| 2688 |
@Redundant[The order of elaboration of library units is determined |
| 2689 |
primarily by the @i{elaboration dependences}.] |
| 2690 |
@Defn2{Term=[elaboration dependence], Sec=(library_item on another)} |
| 2691 |
@Defn2{Term=[dependence], Sec=(elaboration)} |
| 2692 |
There is an elaboration dependence of a given @nt{library_item} upon |
| 2693 |
another if the given @nt{library_item} or any of its subunits depends |
| 2694 |
semantically on the other @nt{library_item}. |
| 2695 |
In addition, if a given @nt{library_item} or any of its subunits |
| 2696 |
has a @nt{pragma} Elaborate or Elaborate_All that |
| 2697 |
@Chg{Version=[2],New=[names],Old=[mentions]} another library unit, |
| 2698 |
then there is an elaboration dependence of the given |
| 2699 |
@nt{library_item} upon the body of the other library unit, |
| 2700 |
and, for Elaborate_All only, upon |
| 2701 |
each @nt{library_item} needed by |
| 2702 |
the declaration of the other library unit. |
| 2703 |
@begin{Discussion} |
| 2704 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0107],ARef=[AI95-00180-01]} |
| 2705 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00256-01]} |
| 2706 |
@ChgAdded{Version=[1],Text=[@Lquotes@;Mentions@rquotes |
| 2707 |
@Chg{Version=[2],New=[was],Old=[is]} |
| 2708 |
used informally in the above rule; it @Chg{Version=[2],New=[was],Old=[is]} |
| 2709 |
not intended to refer to the definition of @i{mentions} in |
| 2710 |
@RefSecNum{Context Clauses - With Clauses}. |
| 2711 |
@Chg{Version=[2],New=[It was changed to @Lquotes@;names@rquotes to make this clear.], |
| 2712 |
Old=[It would have been better to use |
| 2713 |
@Lquotes@;names@rquotes instead of @Lquotes@;mentions@rquotes above.]}]} |
| 2714 |
|
| 2715 |
See above for a definition of which @nt{library_item}s are @lquotes@;needed by@rquotes@; |
| 2716 |
a given declaration. |
| 2717 |
|
| 2718 |
Note that elaboration dependences are among @nt{library_item}s, |
| 2719 |
whereas the other two forms of dependence are among compilation units. |
| 2720 |
Note that elaboration dependence includes semantic dependence. |
| 2721 |
It's a little bit sad that pragma Elaborate_Body can't be folded into |
| 2722 |
this mechanism. |
| 2723 |
It follows from the definition that the elaboration dependence |
| 2724 |
relationship is transitive. |
| 2725 |
Note that the wording of the rule does not need to take into account |
| 2726 |
a semantic dependence of a @nt{library_item} or one of its subunits |
| 2727 |
upon a subunit of a different library unit, |
| 2728 |
because that can never happen. |
| 2729 |
@end{Discussion} |
| 2730 |
|
| 2731 |
@leading@keepnext@;The environment task for a partition has the following |
| 2732 |
structure: |
| 2733 |
@begin{Example} |
| 2734 |
@key[task] @RI{Environment_Task}; |
| 2735 |
|
| 2736 |
@key[task] @key[body] @RI{Environment_Task} @key[is] |
| 2737 |
... (1) --@RI{ The environment }@nt{declarative_part} |
| 2738 |
--@RI{ (that is, the sequence of }@nt{library_item}@RI{s) goes here.} |
| 2739 |
@key[begin] |
| 2740 |
... (2) --@RI{ Call the main subprogram, if there is one.} |
| 2741 |
@key[end] @RI{Environment_Task}; |
| 2742 |
@end{Example} |
| 2743 |
@begin{Ramification} |
| 2744 |
The name of the environment task is written in italics here to indicate |
| 2745 |
that this task is anonymous. |
| 2746 |
@end{Ramification} |
| 2747 |
@begin{Discussion} |
| 2748 |
The model is different for a @lquotes@;passive partition@rquotes@; |
| 2749 |
(see @RefSecNum{Partitions}). |
| 2750 |
Either there is no environment task, or its @nt<sequence_of_statements> |
| 2751 |
is an infinite loop rather than a call on a main subprogram. |
| 2752 |
@end{Discussion} |
| 2753 |
|
| 2754 |
@leading@PDefn2{Term=[environment @nt<declarative_part>], Sec=(for the |
| 2755 |
environment task of a partition)} |
| 2756 |
The environment @nt{declarative_part} at (1) is a sequence of |
| 2757 |
@nt{declarative_item}s consisting of copies of |
| 2758 |
the @nt{library_item}s included in the partition@Redundant[. |
| 2759 |
The order of elaboration of @nt{library_item}s is |
| 2760 |
the order in which they appear in the environment |
| 2761 |
@nt{declarative_part}]: |
| 2762 |
@begin{Itemize} |
| 2763 |
The order of all included @nt<library_item>s |
| 2764 |
is such that there are no forward elaboration |
| 2765 |
dependences. |
| 2766 |
@begin{Ramification} |
| 2767 |
This rule is written so that if a @nt{library_item} |
| 2768 |
depends on itself, we don't require it to be elaborated |
| 2769 |
before itself. See AI83-00113/12. |
| 2770 |
This can happen only in pathological circumstances. |
| 2771 |
For example, if a library @nt{subprogram_body} |
| 2772 |
has no corresponding @nt{subprogram_declaration}, |
| 2773 |
and one of the subunits of the @nt{subprogram_body} |
| 2774 |
mentions the @nt{subprogram_body} in a @nt{with_clause}, |
| 2775 |
the @nt{subprogram_body} will depend on itself. |
| 2776 |
For another example, if a @nt{library_unit_body} |
| 2777 |
applies a @nt{pragma} Elaborate_All to its own declaration, |
| 2778 |
then the @nt{library_unit_body} will depend on itself. |
| 2779 |
@end{Ramification} |
| 2780 |
|
| 2781 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2782 |
Any included @nt{library_unit_declaration} @Chg{Version=[3],New=[for],Old=[to]} |
| 2783 |
which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]} |
| 2784 |
Elaborate_Body @Chg{Version=[3],New=[is True @Redundant[(including when a |
| 2785 |
@nt{pragma} Elaborate_Body applies)]],Old=[applies]} |
| 2786 |
is immediately followed by its @nt{library_unit_body}, |
| 2787 |
if included. |
| 2788 |
@begin{Discussion} |
| 2789 |
This implies that the body of such a library unit |
| 2790 |
shall not @lquotes@;with@rquotes@; any of its own children, |
| 2791 |
or anything else that depends semantically upon |
| 2792 |
the declaration of the library unit. |
| 2793 |
@end{Discussion} |
| 2794 |
@begin{TheProof} |
| 2795 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 2796 |
@ChgAdded{Version=[3],Text=[@nt{Pragma} Elaborate_Body sets |
| 2797 |
aspect Elaborate_Body, see @RefSecNum{Elaboration Control}.]} |
| 2798 |
@end{TheProof} |
| 2799 |
|
| 2800 |
All @nt{library_item}s declared pure occur before any |
| 2801 |
that are not declared pure. |
| 2802 |
|
| 2803 |
All preelaborated @nt<library_item>s occur before any |
| 2804 |
that are not preelaborated. |
| 2805 |
@end{Itemize} |
| 2806 |
@begin{Discussion} |
| 2807 |
Normally, if two partitions contain the same compilation unit, |
| 2808 |
they each contain a separate @i{copy} of that |
| 2809 |
compilation unit. |
| 2810 |
See @RefSec{Distributed Systems} for cases where two partitions share |
| 2811 |
the same copy of something. |
| 2812 |
|
| 2813 |
There is no requirement that the main subprogram be elaborated last. |
| 2814 |
In fact, it is possible to write a partition in which the main |
| 2815 |
subprogram cannot be elaborated last. |
| 2816 |
@end{Discussion} |
| 2817 |
@begin{Ramification} |
| 2818 |
This @nt{declarative_part} has the properties required of all |
| 2819 |
environments (see @RefSecNum{The Compilation Process}). |
| 2820 |
However, the environment @nt{declarative_part} of a partition will |
| 2821 |
typically contain fewer compilation units than the environment |
| 2822 |
@nt{declarative_part} used at compile time @em only the @lquotes@;needed@rquotes@; |
| 2823 |
ones are included in the partition. |
| 2824 |
@end{Ramification} |
| 2825 |
|
| 2826 |
There shall be a total order of the @nt{library_item}s that obeys the |
| 2827 |
above rules. |
| 2828 |
The order is otherwise implementation defined. |
| 2829 |
@begin{Discussion} |
| 2830 |
The only way to violate this rule is to have |
| 2831 |
Elaborate, Elaborate_All, or Elaborate_Body @nt{pragma}s that cause circular ordering |
| 2832 |
requirements, thus preventing an order that has no forward |
| 2833 |
elaboration dependences. |
| 2834 |
@end{Discussion} |
| 2835 |
@ImplDef{The order of elaboration of @nt{library_item}s.} |
| 2836 |
@begin{Honest} |
| 2837 |
@PDefn2{Term=[requires a completion], Sec=(library_unit_declaration)} |
| 2838 |
@Defn{notwithstanding} |
| 2839 |
Notwithstanding what the RM95 says elsewhere, |
| 2840 |
each rule that requires a declaration to have a corresponding |
| 2841 |
completion is considered to be a @LinkTimeName |
| 2842 |
when the declaration is that of a library unit. |
| 2843 |
@end{Honest} |
| 2844 |
@begin{Discussion} |
| 2845 |
Such rules may be checked at @lquotes@;link time,@rquotes@; for example. |
| 2846 |
Rules requiring the completion to have certain properties, |
| 2847 |
on the other hand, are checked at compile time of the completion. |
| 2848 |
@end{Discussion} |
| 2849 |
|
| 2850 |
|
| 2851 |
The full expanded names of the library units and subunits included in a |
| 2852 |
given partition shall be distinct. |
| 2853 |
|
| 2854 |
@begin{Reason} |
| 2855 |
This is a @LinkTimeName because making it a @LegalityName |
| 2856 |
would violate the @MetaRulesName labeled |
| 2857 |
@lquotes@;legality determinable via semantic dependences.@rquotes@; |
| 2858 |
@end{Reason} |
| 2859 |
|
| 2860 |
@leading@;The @nt{sequence_of_statements} of the environment task (see (2) |
| 2861 |
above) consists of either: |
| 2862 |
@begin{Itemize} |
| 2863 |
A call to the main subprogram, |
| 2864 |
if the partition has one. |
| 2865 |
If the main subprogram has parameters, they are passed; |
| 2866 |
where the actuals come from is implementation defined. |
| 2867 |
What happens to the result of a main function is also |
| 2868 |
implementation defined. |
| 2869 |
@ImplDef{Parameter passing and function return for the main |
| 2870 |
subprogram.} |
| 2871 |
@end{Itemize} |
| 2872 |
|
| 2873 |
@leading@keepnext@;or: |
| 2874 |
@begin{Itemize} |
| 2875 |
A @nt{null_statement}, if there is no main subprogram. |
| 2876 |
@begin{Discussion} |
| 2877 |
For a passive partition, either there is no environment task, |
| 2878 |
or its @nt<sequence_of_statements> is an infinite loop. |
| 2879 |
See @RefSecNum{Partitions}. |
| 2880 |
@end{Discussion} |
| 2881 |
@end{Itemize} |
| 2882 |
|
| 2883 |
The mechanisms for building and running partitions are implementation |
| 2884 |
defined. |
| 2885 |
@Redundant[These might be combined into one operation, |
| 2886 |
as, for example, in dynamic linking, or @lquotes@;load-and-go@rquotes@; systems.] |
| 2887 |
@ImplDef{The mechanisms for building and running partitions.} |
| 2888 |
@end{LinkTime} |
| 2889 |
|
| 2890 |
@begin{RunTime} |
| 2891 |
@PDefn2{Term=[execution], Sec=(program)} |
| 2892 |
The execution of a program consists of the execution of a set of |
| 2893 |
partitions. Further details are implementation defined. |
| 2894 |
@PDefn2{Term=[execution], Sec=(partition)} |
| 2895 |
The execution of a partition starts with the execution |
| 2896 |
of its environment task, |
| 2897 |
ends when the environment task terminates, |
| 2898 |
and includes the executions of all tasks of the partition. |
| 2899 |
@Redundant[The execution of the (implicit) @nt<task_body> of the |
| 2900 |
environment task acts as a master |
| 2901 |
for all other tasks created as part of the execution of the partition. |
| 2902 |
When the environment task completes (normally or abnormally), |
| 2903 |
it waits for the termination of all such tasks, |
| 2904 |
and then finalizes any remaining objects of the partition.] |
| 2905 |
@begin{Ramification} |
| 2906 |
The @lquotes@;further details@rquotes@; mentioned above include, |
| 2907 |
for example, program termination @em it |
| 2908 |
is implementation defined. |
| 2909 |
There is no need to define it here; |
| 2910 |
it's entirely up to the implementation whether it wants |
| 2911 |
to consider the program as a whole to exist beyond the existence of |
| 2912 |
individual partitions. |
| 2913 |
@end{Ramification} |
| 2914 |
@ImplDef{The details of program execution, |
| 2915 |
including program termination.} |
| 2916 |
@begin{Honest} |
| 2917 |
@PDefn2{Term=[termination], Sec=(of a partition)} |
| 2918 |
@PDefn2{Term=[normal termination], Sec=(of a partition)} |
| 2919 |
@PDefn2{Term=[termination], Sec=(normal)} |
| 2920 |
@PDefn2{Term=[abnormal termination], Sec=(of a partition)} |
| 2921 |
@PDefn2{Term=[termination], Sec=(abnormal)} |
| 2922 |
The execution of the partition terminates (normally or abnormally) when the |
| 2923 |
environment task terminates (normally or abnormally, respectively). |
| 2924 |
@end{Honest} |
| 2925 |
|
| 2926 |
@end{RunTime} |
| 2927 |
|
| 2928 |
@begin{Bounded} |
| 2929 |
@PDefn2{Term=(bounded error),Sec=(cause)} |
| 2930 |
@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)} |
| 2931 |
Once the environment task has awaited the termination of all other |
| 2932 |
tasks of the partition, any further attempt to create a task |
| 2933 |
(during finalization) is a bounded error, and may result in |
| 2934 |
the raising of Program_Error either upon creation or activation |
| 2935 |
of the task. |
| 2936 |
@PDefn{unspecified} |
| 2937 |
If such a task is activated, it is not specified |
| 2938 |
whether the task is awaited prior to termination of the |
| 2939 |
environment task. |
| 2940 |
@end{Bounded} |
| 2941 |
|
| 2942 |
@begin{ImplReq} |
| 2943 |
@Leading@;The implementation shall ensure that all compilation units |
| 2944 |
included in a partition are consistent with one another, |
| 2945 |
and are legal according to the rules of the language. |
| 2946 |
@begin{Discussion} |
| 2947 |
The consistency requirement implies that |
| 2948 |
a partition cannot contain two versions of the same compilation unit. |
| 2949 |
That is, |
| 2950 |
a partition cannot contain two different library units with the |
| 2951 |
same full expanded name, nor two different bodies for the same |
| 2952 |
program unit. |
| 2953 |
For example, suppose we compile the following: |
| 2954 |
@begin{Example} |
| 2955 |
@key[package] A @key[is] --@RI{ Version 1.} |
| 2956 |
... |
| 2957 |
@key[end] A; |
| 2958 |
|
| 2959 |
@key[with] A; |
| 2960 |
@key[package] B @key[is] |
| 2961 |
@key[end] B; |
| 2962 |
|
| 2963 |
@key[package] A @key[is] --@RI{ Version 2.} |
| 2964 |
... |
| 2965 |
@key[end] A; |
| 2966 |
|
| 2967 |
@key[with] A; |
| 2968 |
@key[package] C @key[is] |
| 2969 |
@key[end] C; |
| 2970 |
@end{Example} |
| 2971 |
|
| 2972 |
It would be wrong for a partition containing B and C to contain both |
| 2973 |
versions of A. |
| 2974 |
Typically, the implementation would require the use of Version 2 of A, |
| 2975 |
which might require the recompilation of B. |
| 2976 |
Alternatively, the implementation might automatically recompile B |
| 2977 |
when the partition is built. |
| 2978 |
A third alternative would be an incremental compiler that, |
| 2979 |
when Version 2 of A is compiled, |
| 2980 |
automatically patches the object code for B to reflect the changes to |
| 2981 |
A (if there are any relevant changes @em there might not be any). |
| 2982 |
|
| 2983 |
An implementation that supported fancy version management |
| 2984 |
might allow the use of Version 1 in some circumstances. |
| 2985 |
In no case can the implementation allow the use of both versions in |
| 2986 |
the same partition |
| 2987 |
(unless, of course, it can prove that the two versions are |
| 2988 |
semantically identical). |
| 2989 |
|
| 2990 |
The core language says nothing about inter-partition |
| 2991 |
consistency; see also @RefSec{Distributed Systems}. |
| 2992 |
@end{Discussion} |
| 2993 |
@end{ImplReq} |
| 2994 |
|
| 2995 |
@begin{ImplPerm} |
| 2996 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 2997 |
@Defn{active partition} |
| 2998 |
The kind of partition described in this @Chg{Version=[3],New=[subclause],Old=[clause]} |
| 2999 |
is known as an @i{active} partition. |
| 3000 |
An implementation is allowed to support other kinds of partitions, |
| 3001 |
with implementation-defined semantics. |
| 3002 |
@ImplDef{The semantics of any nonactive partitions supported by the |
| 3003 |
implementation.} |
| 3004 |
@begin{Discussion} |
| 3005 |
@RefSec{Distributed Systems} defines the concept of passive partitions; |
| 3006 |
they may be thought of as a partition without an environment task, |
| 3007 |
or as one with a particularly simple form of environment task, |
| 3008 |
having an infinite loop rather than a call on a main subprogram |
| 3009 |
as its @nt<sequence_of_statements>. |
| 3010 |
@end{Discussion} |
| 3011 |
|
| 3012 |
An implementation may restrict the kinds of subprograms it supports |
| 3013 |
as main subprograms. |
| 3014 |
However, an implementation is required to support all main |
| 3015 |
subprograms that are public parameterless library procedures. |
| 3016 |
@begin{Ramification} |
| 3017 |
The implementation is required to support main subprograms that are |
| 3018 |
procedures declared by @nt{generic_instantiation}s, |
| 3019 |
as well as those |
| 3020 |
that are children of library units other than Standard. |
| 3021 |
Generic units are, of course, not allowed to be main subprograms, |
| 3022 |
since they are not subprograms. |
| 3023 |
|
| 3024 |
Note that renamings are irrelevant to this rule. |
| 3025 |
This rules says which subprograms (not views) |
| 3026 |
have to be supported. |
| 3027 |
The implementation can choose any way it wants for the |
| 3028 |
user to indicate which subprogram should be the main subprogram. |
| 3029 |
An implementation might allow any name of any view, |
| 3030 |
including those declared by renamings. |
| 3031 |
Another implementation might require it to be the original name. |
| 3032 |
Another implementation still might use the name of the source file or |
| 3033 |
some such thing. |
| 3034 |
@end{Ramification} |
| 3035 |
|
| 3036 |
If the environment task completes abnormally, |
| 3037 |
the implementation may abort any dependent tasks. |
| 3038 |
@begin{Reason} |
| 3039 |
If the implementation does not take advantage of this permission, |
| 3040 |
the normal action takes place @em the environment task awaits those |
| 3041 |
tasks. |
| 3042 |
|
| 3043 |
The possibility of aborting them |
| 3044 |
is not shown in the @i{Environment_Task} code above, |
| 3045 |
because there is nowhere to put an @nt{exception_handler} that can |
| 3046 |
handle exceptions raised in both the environment @nt{declarative_part} |
| 3047 |
and the main subprogram, |
| 3048 |
such that the dependent tasks can be aborted. |
| 3049 |
If we put an @nt{exception_handler} in the body of the environment |
| 3050 |
task, then it won't handle exceptions that occur during elaboration of |
| 3051 |
the environment @nt{declarative_part}. |
| 3052 |
If we were to move those things into a nested @nt{block_statement}, |
| 3053 |
with the @nt{exception_handler} outside that, |
| 3054 |
then the @nt{block_statement} would await the library tasks we are |
| 3055 |
trying to abort. |
| 3056 |
|
| 3057 |
Furthermore, this is merely a permission, and is not fundamental to the |
| 3058 |
model, so it is probably better to state it separately anyway. |
| 3059 |
|
| 3060 |
Note that implementations (and tools like debuggers) |
| 3061 |
can have modes that provide other behaviors in addition. |
| 3062 |
@end{Reason} |
| 3063 |
@end{ImplPerm} |
| 3064 |
|
| 3065 |
@begin{Notes} |
| 3066 |
An implementation may provide inter-partition |
| 3067 |
communication mechanism(s) via special packages and pragmas. |
| 3068 |
Standard pragmas for distribution and methods for specifying |
| 3069 |
inter-partition communication are defined in @RefSec{Distributed Systems}. |
| 3070 |
If no such mechanisms are provided, then each partition is isolated from all |
| 3071 |
others, and behaves as a program in and of itself. |
| 3072 |
@begin{Ramification} |
| 3073 |
Not providing such mechanisms is equivalent to disallowing multi-partition |
| 3074 |
programs. |
| 3075 |
|
| 3076 |
An implementation may provide mechanisms to facilitate checking the |
| 3077 |
consistency of library units elaborated in different partitions; |
| 3078 |
@RefSec{Distributed Systems} does so. |
| 3079 |
@end{Ramification} |
| 3080 |
|
| 3081 |
Partitions are not required to run in separate address spaces. |
| 3082 |
For example, an implementation might support dynamic linking |
| 3083 |
via the partition concept. |
| 3084 |
|
| 3085 |
An order of elaboration of @nt{library_item}s that is consistent with |
| 3086 |
the partial ordering defined above does not always ensure that each |
| 3087 |
@nt{library_unit_body} is elaborated before any other compilation unit |
| 3088 |
whose elaboration necessitates that the @nt{library_unit_body} be |
| 3089 |
already elaborated. |
| 3090 |
(In particular, there is no requirement that the body of a library unit |
| 3091 |
be elaborated as soon as possible after the |
| 3092 |
@nt{library_unit_declaration} is elaborated, |
| 3093 |
unless the pragmas in subclause @RefSecNum{Elaboration Control} are |
| 3094 |
used.) |
| 3095 |
|
| 3096 |
A partition (active or otherwise) need not have a main subprogram. |
| 3097 |
In such a case, all the work done by the partition would be done by |
| 3098 |
elaboration of various @nt{library_item}s, and by tasks created by that |
| 3099 |
elaboration. |
| 3100 |
Passive partitions, which cannot have main subprograms, |
| 3101 |
are defined in @RefSec{Distributed Systems}. |
| 3102 |
@begin{Ramification} |
| 3103 |
The environment task is the outermost semantic level |
| 3104 |
defined by the language. |
| 3105 |
|
| 3106 |
Standard has no private part. |
| 3107 |
This prevents strange implementation-dependences involving private |
| 3108 |
children of Standard having visibility upon Standard's private part. |
| 3109 |
It doesn't matter where the body of Standard appears in the environment, |
| 3110 |
since it doesn't do anything. |
| 3111 |
See @RefSec{Predefined Language Environment}. |
| 3112 |
|
| 3113 |
Note that elaboration dependence is carefully defined in such a way that |
| 3114 |
if (say) the body of something doesn't exist yet, |
| 3115 |
then there is no elaboration dependence upon the nonexistent body. |
| 3116 |
(This follows from the fact that @lquotes@;needed by@rquotes@; is defined that way, |
| 3117 |
and the elaboration dependences caused by a @nt{pragma} Elaborate or |
| 3118 |
Elaborate_All are defined in terms of @lquotes@;needed by@rquotes@;.) |
| 3119 |
This property allows us to use the environment concept both at compile |
| 3120 |
time and at partition-construction time/run time. |
| 3121 |
@end{Ramification} |
| 3122 |
@end{Notes} |
| 3123 |
|
| 3124 |
@begin{Extend83} |
| 3125 |
@Defn{extensions to Ada 83} |
| 3126 |
The concept of partitions is new to Ada 95. |
| 3127 |
|
| 3128 |
A main subprogram is now optional. |
| 3129 |
The language-defined restrictions on main subprograms are relaxed. |
| 3130 |
@end{Extend83} |
| 3131 |
|
| 3132 |
@begin{DiffWord83} |
| 3133 |
Ada 95 uses the term @lquotes@;main subprogram@rquotes@; instead of Ada 83's @lquotes@;main |
| 3134 |
program@rquotes@; (which was inherited from Pascal). |
| 3135 |
This is done to avoid confusion @em a main subprogram is a subprogram, not a |
| 3136 |
program. |
| 3137 |
The program as a whole is an entirely different thing. |
| 3138 |
@end{DiffWord83} |
| 3139 |
|
| 3140 |
@begin{DiffWord95} |
| 3141 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00256-01]} |
| 3142 |
@ChgAdded{Version=[2],Text=[The mistaken use of @lquotes@;mentions@rquotes@; |
| 3143 |
in the elaboration dependence rule was fixed.]} |
| 3144 |
|
| 3145 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 3146 |
@ChgAdded{Version=[2],Text=[The @i<needs> relationship was extended to |
| 3147 |
include limited views.]} |
| 3148 |
@end{DiffWord95} |
| 3149 |
|
| 3150 |
@LabeledSubClause{Elaboration Control} |
| 3151 |
|
| 3152 |
@begin{Intro} |
| 3153 |
@Redundant[@Defn{elaboration control} |
| 3154 |
This subclause defines pragmas that help control |
| 3155 |
the elaboration order of @nt{library_item}s.] |
| 3156 |
@end{Intro} |
| 3157 |
|
| 3158 |
@begin{MetaRules} |
| 3159 |
The rules governing preelaboration are designed to allow |
| 3160 |
it to be done largely by bulk initialization of statically |
| 3161 |
allocated storage from information in a @lquotes@;load module@rquotes@; created by a linker. |
| 3162 |
Some implementations may require run-time code to be executed in some |
| 3163 |
cases, but we consider these cases rare enough that we need not |
| 3164 |
further complicate the rules. |
| 3165 |
|
| 3166 |
It is important that programs be able to declare data structures that |
| 3167 |
are link-time initialized with @nt{aggregate}s, @nt{string_literal}s, |
| 3168 |
and concatenations thereof. |
| 3169 |
It is important to be able to write link-time evaluated expressions |
| 3170 |
involving the First, Last, and Length attributes of such data structures |
| 3171 |
(including variables), because they might be initialized with positional |
| 3172 |
@nt{aggregate}s or @nt{string_literal}s, and we don't want the user to |
| 3173 |
have to count the elements. |
| 3174 |
There is no corresponding need for accessing discriminants, |
| 3175 |
since they can be initialized with a static constant, |
| 3176 |
and then the constant can be referred to elsewhere. |
| 3177 |
It is important to allow link-time initialized data structures |
| 3178 |
involving discriminant-dependent components. |
| 3179 |
It is important to be able to write link-time evaluated expressions |
| 3180 |
involving pointers (both access values and addresses) |
| 3181 |
to the above-mentioned data structures. |
| 3182 |
|
| 3183 |
The rules also ensure that no Elaboration_Check need be performed |
| 3184 |
for calls on library-level subprograms declared within |
| 3185 |
a preelaborated package. |
| 3186 |
This is true also of the Elaboration_Check on task activation |
| 3187 |
for library level task types declared in a preelaborated package. |
| 3188 |
However, it is not true of the Elaboration_Check on instantiations. |
| 3189 |
|
| 3190 |
A static expression should never prevent a library unit from being |
| 3191 |
preelaborable. |
| 3192 |
|
| 3193 |
|
| 3194 |
@end{MetaRules} |
| 3195 |
|
| 3196 |
@begin{Syntax} |
| 3197 |
@begin{SyntaxText} |
| 3198 |
@Leading@Keepnext@;The form of a @nt{pragma} Preelaborate is as follows: |
| 3199 |
@end{SyntaxText} |
| 3200 |
|
| 3201 |
@PragmaSyn`@key{pragma} @prag(Preelaborate)[(@SynI{library_unit_}@Syn2{name})];' |
| 3202 |
|
| 3203 |
@begin{SyntaxText} |
| 3204 |
@PDefn2{Term=[library unit pragma], Sec=(Preelaborate)} |
| 3205 |
@PDefn2{Term=[pragma, library unit], Sec=(Preelaborate)} |
| 3206 |
A @nt{pragma} Preelaborate is a library unit pragma. |
| 3207 |
@end{SyntaxText} |
| 3208 |
|
| 3209 |
@begin{SyntaxText} |
| 3210 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]} |
| 3211 |
@ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],Text=[The form of a |
| 3212 |
@nt{pragma} Preelaborable_Initialization is as follows:]} |
| 3213 |
@end{SyntaxText} |
| 3214 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3215 |
@AddedPragmaSyn{Version=[2],@ChgAdded{Version=[2], |
| 3216 |
Text=<@key{pragma} @prag<Preelaborable_Initialization>(@Syn2{direct_name});>}} |
| 3217 |
@end{Syntax} |
| 3218 |
|
| 3219 |
@begin{Legality} |
| 3220 |
@Leading@RootDefn2{Term=[preelaborable], Sec=(of an elaborable construct)} |
| 3221 |
An elaborable construct is preelaborable unless its |
| 3222 |
elaboration performs any of the following actions: |
| 3223 |
@begin{Ramification} |
| 3224 |
A @i{preelaborable} construct can be elaborated |
| 3225 |
without using any information that is available only at run time. |
| 3226 |
Note that we don't try to prevent exceptions in preelaborable |
| 3227 |
constructs; if the implementation wishes to generate code to |
| 3228 |
raise an exception, that's OK. |
| 3229 |
|
| 3230 |
Because there is no flow of control and there are no calls |
| 3231 |
(other than to predefined subprograms), |
| 3232 |
these run-time properties can actually be detected at compile |
| 3233 |
time. |
| 3234 |
This is necessary in order to require compile-time enforcement of the |
| 3235 |
rules. |
| 3236 |
@end{Ramification} |
| 3237 |
@begin{Itemize} |
| 3238 |
The execution of a @nt{statement} other than a @nt{null_statement}. |
| 3239 |
@begin{Ramification} |
| 3240 |
A preelaborable construct can contain @nt{label}s and |
| 3241 |
@nt{null_statement}s. |
| 3242 |
@end{Ramification} |
| 3243 |
|
| 3244 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0175-1]} |
| 3245 |
@ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{To get conditional Leading}A |
| 3246 |
call to a subprogram other than@Chg{Version=[5],New=[:],Old=[ a static function.]} |
| 3247 |
@begin{Itemize} |
| 3248 |
@ChgRef{Version=[5],Kind=[Added]} |
| 3249 |
@ChgAdded{Version=[5],Text=[a static function;]} |
| 3250 |
|
| 3251 |
@ChgRef{Version=[5],Kind=[Added]} |
| 3252 |
@ChgAdded{Version=[5],Text=[an instance of Unchecked_Conversion (see |
| 3253 |
@RefSecNum{Unchecked Type Conversions});]} |
| 3254 |
|
| 3255 |
@ChgRef{Version=[5],Kind=[Added]} |
| 3256 |
@ChgAdded{Version=[5],Text=[a function declared in System.Storage_Elements |
| 3257 |
(see @RefSecNum{The Package System.Storage_Elements}); or]} |
| 3258 |
|
| 3259 |
@ChgRef{Version=[5],Kind=[Added]} |
| 3260 |
@ChgAdded{Version=[5],Text=[the functions To_Pointer and To_Address declared |
| 3261 |
in an instance of System.Address_to_Access_Conversions (see |
| 3262 |
@RefSecNum{The Package System.Address_to_Access_Conversions}).]} |
| 3263 |
@end{Itemize} |
| 3264 |
@begin{Ramification} |
| 3265 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0175-1]} |
| 3266 |
@ChgAdded{Version=[5],Text=[The parameters of any such function have to pass |
| 3267 |
the preelaborability rules, so they typically have to be static |
| 3268 |
expressions. The extra allowed functions are all forms of conversion that the |
| 3269 |
compiler understands, so there should be little implementation burden. Note |
| 3270 |
that such a call might raise an exception; preelaborable is not the same as |
| 3271 |
elaborable with no code.]} |
| 3272 |
@end{Ramification} |
| 3273 |
|
| 3274 |
The evaluation of a @nt{primary} that is a @nt{name} |
| 3275 |
of an object, unless the @nt{name} is a static expression, |
| 3276 |
or statically denotes a discriminant of an enclosing type. |
| 3277 |
@begin{Ramification} |
| 3278 |
One can evaluate such a @nt{name}, but not as a @nt{primary}. |
| 3279 |
For example, one can evaluate an attribute of the object. |
| 3280 |
One can evaluate an @nt{attribute_reference}, |
| 3281 |
so long as it does not denote an object, |
| 3282 |
and its @nt{prefix} does not disobey any of these rules. |
| 3283 |
For example, Obj'Access, Obj'Unchecked_Access, |
| 3284 |
and Obj'Address are generally legal in preelaborated library |
| 3285 |
units. |
| 3286 |
@end{Ramification} |
| 3287 |
|
| 3288 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]} |
| 3289 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0028-1]} |
| 3290 |
The creation of @Chg{Version=[2],New=[an object @Redundant[(including a |
| 3291 |
component)] @Chg{Version=[3],New=[that is initialized by default, if |
| 3292 |
its],Old=[of a]} type @Chg{Version=[3],New=[],Old=[that ]}does not have |
| 3293 |
preelaborable initialization. Similarly,], |
| 3294 |
Old=[a default-initialized object @Redundant[(including |
| 3295 |
a component)] of a descendant of a private type, |
| 3296 |
private extension, controlled type, |
| 3297 |
task type, or protected type with |
| 3298 |
@nt{entry_@!declaration}s; similarly]} the evaluation of |
| 3299 |
an @nt<extension_@!aggregate> with |
| 3300 |
an ancestor @nt<subtype_@!mark> denoting a subtype of such a type. |
| 3301 |
|
| 3302 |
@begin{Ramification} |
| 3303 |
One can declare these kinds of types, |
| 3304 |
but one cannot create objects of those types. |
| 3305 |
|
| 3306 |
It is also nonpreelaborable to create an object if that will cause the |
| 3307 |
evaluation of a default expression that will call a user-defined |
| 3308 |
function. |
| 3309 |
This follows from the rule above forbidding nonnull statements. |
| 3310 |
@end{Ramification} |
| 3311 |
@begin{Reason} |
| 3312 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00161-01]} |
| 3313 |
@ChgDeleted{Version=[2],Text=[Controlled objects are disallowed because most |
| 3314 |
implementations will have to take some run-time action during initialization, |
| 3315 |
even if the Initialize procedure is null.]} |
| 3316 |
@end{Reason} |
| 3317 |
|
| 3318 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0232-1]} |
| 3319 |
@ChgAdded{Version=[5],Text=[The elaboration of any elaborable construct that |
| 3320 |
is not preelaborable.]} |
| 3321 |
@end{Itemize} |
| 3322 |
|
| 3323 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0232-1]} |
| 3324 |
@ChgAdded{Version=[5],Text=[A generic declaration is preelaborable unless every |
| 3325 |
instance would perform one of the above actions.]} |
| 3326 |
|
| 3327 |
@begin{Ramification} |
| 3328 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0232-1]} |
| 3329 |
@ChgAdded{Version=[5],Text=[A generic declaration is preelaborable unless |
| 3330 |
there is no instance that could be declared preelaborated. For instance, |
| 3331 |
a generic package declaration that directly contains a variable initialized |
| 3332 |
by a non-static function that is not a formal function is not preelaborable |
| 3333 |
(and thus would be illegal if pragma Preelaborate were applied to it).]} |
| 3334 |
@end{Ramification} |
| 3335 |
|
| 3336 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00403-01]} |
| 3337 |
@ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Phony addition to get conditional leading} |
| 3338 |
A generic body is |
| 3339 |
preelaborable only if elaboration of a corresponding |
| 3340 |
instance body would not perform any such actions, |
| 3341 |
presuming that@Chg{Version=[2],New=[:],Old=[ the actual for each formal |
| 3342 |
private type (or extension) is |
| 3343 |
a private type (or extension), and the actual for each |
| 3344 |
formal subprogram is a user-defined subprogram.]} |
| 3345 |
@Defn{generic contract issue} |
| 3346 |
@begin{Itemize} |
| 3347 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]} |
| 3348 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI95-0028-1]} |
| 3349 |
@ChgAdded{Version=[2],Text=[the actual for each@Chg{Version=[3], |
| 3350 |
New=[ discriminated formal derived type,],Old=[]} formal private |
| 3351 |
type@Chg{Version=[3],New=[, ],Old=[ (]}or |
| 3352 |
@Chg{Version=[3],New=[formal private ],Old=[]}extension@Chg{Version=[3],New=[],Old=[)]} |
| 3353 |
declared within the formal part of the generic unit is |
| 3354 |
a @Chg{Version=[3],New=[],Old=[private ]}type@Chg{Version=[3],New=[],Old=[ (or extension)]} |
| 3355 |
that does not have preelaborable initialization@Chg{Version=[3], |
| 3356 |
New=[, unless @nt<pragma> |
| 3357 |
Preelaborable_Initialization has been applied to the formal type],Old=[]};]} |
| 3358 |
|
| 3359 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]} |
| 3360 |
@ChgAdded{Version=[2],Text=[the actual for each formal type is nonstatic;]} |
| 3361 |
|
| 3362 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]} |
| 3363 |
@ChgAdded{Version=[2],Text=[the actual for each formal object is nonstatic; and]} |
| 3364 |
|
| 3365 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]} |
| 3366 |
@ChgAdded{Version=[2],Text=[the actual for each formal subprogram is a |
| 3367 |
user-defined subprogram.]} |
| 3368 |
@end{Itemize} |
| 3369 |
@begin{Discussion} |
| 3370 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]} |
| 3371 |
@ChgAdded{Version=[2],Text=[This is an @lquotes@;assume-the-worst@rquotes |
| 3372 |
rule. The elaboration of a generic unit doesn't perform any of the actions |
| 3373 |
listed above, because its sole effect is to establish that the generic can |
| 3374 |
from now on be instantiated. So the elaboration of the generic itself is not |
| 3375 |
the interesting part when it comes to preelaboration rules. The interesting |
| 3376 |
part is what happens when you elaborate @lquotes@;any instantiation@rquotes |
| 3377 |
of the generic. For instance, declaring an object of a limited formal private |
| 3378 |
type might well start tasks, call functions, and do all sorts of |
| 3379 |
nonpreelaborable things. We prevent these situations by assuming that the |
| 3380 |
actual parameters are as badly behaved as possible.]} |
| 3381 |
@end{Discussion} |
| 3382 |
@begin{Reason} |
| 3383 |
Without this rule about generics, we would have to forbid |
| 3384 |
instantiations in preelaborated library units, |
| 3385 |
which would significantly reduce their usefulness. |
| 3386 |
@end{Reason} |
| 3387 |
|
| 3388 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]} |
| 3389 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0034-1],ARef=[AI05-0243-1]} |
| 3390 |
@PDefn{preelaborated} |
| 3391 |
@Chg{Version=[3],New=[A],Old=[If a]} @nt{pragma} Preelaborate (or |
| 3392 |
@nt<pragma> Pure @em see below) @Chg{Version=[3],New=[is used to specify that], |
| 3393 |
Old=[applies to]} |
| 3394 |
a library unit@Chg{Version=[3],New=[],Old=[, then it]} is |
| 3395 |
@i{preelaborated}@Chg{Version=[3],New=[, namely that the Preelaborate |
| 3396 |
aspect@AspectDefn{Preelaborate} of the library unit is True; all |
| 3397 |
compilation units of the |
| 3398 |
library unit are preelaborated],Old=[]}. |
| 3399 |
@Chg{Version=[3],New=[],Old=[@Redundant[ |
| 3400 |
@RootDefn{preelaborated} |
| 3401 |
If a library unit is preelaborated, then its declaration, if any, |
| 3402 |
and body, if any, are elaborated |
| 3403 |
prior to all nonpreelaborated @nt{library_item}s of the partition.] |
| 3404 |
]}@Chg{New=[The declaration and body of a preelaborated library |
| 3405 |
unit, and all subunits that are elaborated as part of elaborating the library |
| 3406 |
unit,], Old=[All compilation units of a preelaborated |
| 3407 |
library unit]} shall be preelaborable.@Chg{Version=[3],New=[ |
| 3408 |
All |
| 3409 |
compilation units of a preelaborated library unit shall depend semantically only |
| 3410 |
on declared pure or preelaborated @nt{library_item}s.],Old=[]} |
| 3411 |
@PDefn{generic contract issue} |
| 3412 |
In addition to the places where @LegalityTitle normally apply |
| 3413 |
(see @RefSecNum{Generic Instantiation}), |
| 3414 |
@Chg{Version=[3],New=[these rules also apply],Old=[this rule applies also]} |
| 3415 |
in the private part of an instance of a generic unit. |
| 3416 |
@Chg{Version=[3],New=[@Redundant[ |
| 3417 |
@RootDefn{preelaborated} |
| 3418 |
If a library unit is preelaborated, then its declaration, if any, |
| 3419 |
and body, if any, are elaborated |
| 3420 |
prior to all nonpreelaborated @nt{library_item}s of the partition.]], |
| 3421 |
Old=[In addition, all compilation units of a preelaborated library unit |
| 3422 |
shall depend semantically only on |
| 3423 |
compilation units of other preelaborated library units.]} |
| 3424 |
@begin{Ramification} |
| 3425 |
In a generic body, we assume the worst about |
| 3426 |
formal private types and extensions. |
| 3427 |
|
| 3428 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0035],ARef=[AI95-00002-01]} |
| 3429 |
@ChgAdded{Version=[1],Text=[Subunits of a preelaborated subprogram unit |
| 3430 |
do not need |
| 3431 |
to be preelaborable. This is needed in order to be consistent with units |
| 3432 |
nested in a subprogram body, which do not need to be preelaborable even if |
| 3433 |
the subprogram is preelaborated. However, such subunits cannot depend |
| 3434 |
semantically on nonpreelaborated units, which is also consistent with |
| 3435 |
nested units.]} |
| 3436 |
@end{Ramification} |
| 3437 |
|
| 3438 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Preelaborate], |
| 3439 |
Text=[@ChgAdded{Version=[3],Text=[Code execution during elaboration is |
| 3440 |
avoided for a given package.]}]} |
| 3441 |
|
| 3442 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]} |
| 3443 |
@ChgAdded{Version=[2],Text=[@defn{preelaborable initialization}The following rules |
| 3444 |
specify which entities have @i{preelaborable initialization}:]} |
| 3445 |
|
| 3446 |
@begin{Itemize} |
| 3447 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3448 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1]} |
| 3449 |
@ChgAdded{Version=[2],Text=[The partial view |
| 3450 |
of a private type or private extension, a protected type without |
| 3451 |
@nt<entry_declaration>s, a generic formal private type, or a generic formal |
| 3452 |
derived type, @Chg{Version=[3],New=[has],Old=[have]} preelaborable |
| 3453 |
initialization if and only if the @nt<pragma> Preelaborable_Initialization has |
| 3454 |
been applied to them. @Redundant[A protected type with @nt{entry_declaration}s |
| 3455 |
or a task type never has preelaborable initialization.]]} |
| 3456 |
|
| 3457 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3458 |
@ChgAdded{Version=[2],Text=[A component (including a discriminant) of a record or |
| 3459 |
protected type has preelaborable initialization if its declaration includes a |
| 3460 |
@nt<default_expression> whose execution does not perform any actions prohibited |
| 3461 |
in preelaborable constructs as described above, or if its declaration does not |
| 3462 |
include a default expression and its type has preelaborable |
| 3463 |
initialization.]} |
| 3464 |
|
| 3465 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3466 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1],ARef=[AI05-0221-1]} |
| 3467 |
@ChgAdded{Version=[2],Text=[A derived type has preelaborable initialization |
| 3468 |
if its parent type has preelaborable initialization and |
| 3469 |
@Chg{Version=[3],New=[],Old=[(in the case of a |
| 3470 |
derived record extension) ]}if the noninherited components all have |
| 3471 |
preelaborable initialization. However, a @Chg{Version=[3],New=[], |
| 3472 |
Old=[user-defined ]}controlled type with an |
| 3473 |
@Chg{Version=[3],New=[],Old=[overriding ]}Initialize procedure |
| 3474 |
@Chg{Version=[3],New=[that is not a null procedure ],Old=[]}does not |
| 3475 |
have preelaborable initialization.]} |
| 3476 |
|
| 3477 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01],ARef=[AI95-00345-01]} |
| 3478 |
@ChgAdded{Version=[2],Text=[A view of a type has preelaborable initialization if it |
| 3479 |
is an elementary type, an array type whose component type has preelaborable |
| 3480 |
initialization, a record type whose components all have preelaborable |
| 3481 |
initialization, or an interface type.]} |
| 3482 |
@end{Itemize} |
| 3483 |
|
| 3484 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]} |
| 3485 |
@ChgAdded{Version=[2],Text=[A @nt<pragma> Preelaborable_Initialization specifies that a type has |
| 3486 |
preelaborable initialization. This pragma shall appear in the visible part |
| 3487 |
of a package or generic package.]} |
| 3488 |
|
| 3489 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01],ARef=[AI95-00345-01]} |
| 3490 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1]} |
| 3491 |
@ChgAdded{Version=[2],Text=[If the pragma appears in the first list of |
| 3492 |
@nt{basic_declarative_item}s of a |
| 3493 |
@nt<package_specification>, then the @nt<direct_name> shall denote the first |
| 3494 |
subtype of a @Chg{Version=[3],New=[composite],Old=[private]} |
| 3495 |
type@Chg{Version=[3],New=[],Old=[, private extension, or protected type that is not |
| 3496 |
an interface type and is without |
| 3497 |
@nt<entry_declaration>s]}, and the type shall be declared immediately within |
| 3498 |
the same package |
| 3499 |
as the @nt<pragma>. If the @nt<pragma> is applied to a private type or a |
| 3500 |
private extension, the full view of the type shall have preelaborable |
| 3501 |
initialization. If the @nt<pragma> is applied to a protected type, |
| 3502 |
@Chg{Version=[3],New=[the protected type shall not have |
| 3503 |
entries, and ],Old=[]}each |
| 3504 |
component of the protected type shall have preelaborable initialization. |
| 3505 |
@Chg{Version=[3],New=[For any other composite type, the type shall have |
| 3506 |
preelaborable initialization. ],Old=[]}@PDefn{generic contract issue}In |
| 3507 |
addition to the places where @LegalityTitle normally apply |
| 3508 |
(see @RefSecNum{Generic Instantiation}), these rules apply |
| 3509 |
also in the private part of an instance of a generic unit.]} |
| 3510 |
|
| 3511 |
@begin{Reason} |
| 3512 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1]} |
| 3513 |
@ChgAdded{Version=[3],Text=[The reason why we need the pragma for private |
| 3514 |
types, private extensions, and protected types is fairly clear: the |
| 3515 |
properties of the full view determine whether the type has preelaborable |
| 3516 |
initialization or not; in order to preserve privacy we need a way to express |
| 3517 |
on the partial view that the full view is well-behaved. The reason why we |
| 3518 |
need the pragma for other composite types is more subtle: a nonnull override |
| 3519 |
for Initialize might occur in the private part, even for a nonprivate type; |
| 3520 |
in order to preserve privacy, we need a way to express on a type declared in |
| 3521 |
a visible part that the private part does not contain any nasty override of |
| 3522 |
Initialize.]} |
| 3523 |
@end{Reason} |
| 3524 |
|
| 3525 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]} |
| 3526 |
@ChgAdded{Version=[2],Text=[If the @nt<pragma> appears in a @nt<generic_formal_part>, then the |
| 3527 |
@nt<direct_name> shall denote a generic formal private type or a generic formal |
| 3528 |
derived type declared in the same @nt<generic_formal_part> as the @nt<pragma>. |
| 3529 |
In a @nt<generic_instantiation> the corresponding actual type shall have |
| 3530 |
preelaborable initialization.]} |
| 3531 |
|
| 3532 |
@begin{Ramification} |
| 3533 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3534 |
@ChgAdded{Version=[2],Text=[Not only do protected types with |
| 3535 |
@nt{entry_declaration}s |
| 3536 |
and task types not have preelaborable initialization, but they cannot have |
| 3537 |
pragma Preelaborable_Initialization applied to them.]} |
| 3538 |
@end{Ramification} |
| 3539 |
@end{Legality} |
| 3540 |
|
| 3541 |
@begin{ImplAdvice} |
| 3542 |
In an implementation, a type declared in a preelaborated package |
| 3543 |
should have the same representation in every elaboration |
| 3544 |
of a given version of the package, |
| 3545 |
whether the elaborations occur in distinct executions of |
| 3546 |
the same program, or in executions of distinct programs or partitions |
| 3547 |
that include the given version. |
| 3548 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 3549 |
Text=[A type declared in a preelaborated package |
| 3550 |
should have the same representation in every elaboration |
| 3551 |
of a given version of the package.]}]} |
| 3552 |
@end{ImplAdvice} |
| 3553 |
|
| 3554 |
@begin{Syntax} |
| 3555 |
@begin{SyntaxText} |
| 3556 |
@leading@keepnext@;The form of a @nt{pragma} Pure is as follows: |
| 3557 |
@end{SyntaxText} |
| 3558 |
|
| 3559 |
@PragmaSyn`@key{pragma} @prag(Pure)[(@SynI{library_unit_}@Syn2{name})];' |
| 3560 |
|
| 3561 |
@begin{SyntaxText} |
| 3562 |
@PDefn2{Term=[library unit pragma], Sec=(Pure)} |
| 3563 |
@PDefn2{Term=[pragma, library unit], Sec=(Pure)} |
| 3564 |
A @nt{pragma} Pure is a library unit pragma. |
| 3565 |
@end{SyntaxText} |
| 3566 |
@end{Syntax} |
| 3567 |
|
| 3568 |
@begin{StaticSem} |
| 3569 |
|
| 3570 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00366-01]} |
| 3571 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]} |
| 3572 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0232-1]} |
| 3573 |
@ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{pure} |
| 3574 |
A @i{pure} @Chg{Version=[3],New=[@Chg{Version=[5],New=[program],Old=[compilation]} |
| 3575 |
unit],Old=[@nt{library_item}]} is a preelaborable |
| 3576 |
@Chg{Version=[3],New=[@Chg{Version=[5],New=[program],Old=[compilation]} |
| 3577 |
unit],Old=[@nt{library_item}]} whose |
| 3578 |
elaboration does not perform any of the following actions:]} |
| 3579 |
|
| 3580 |
@begin{Itemize} |
| 3581 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3582 |
@ChgAdded{Version=[2],Text=[the elaboration of a variable declaration;]} |
| 3583 |
|
| 3584 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3585 |
@ChgAdded{Version=[2],Text=[the evaluation of an @nt{allocator} of an |
| 3586 |
access-to-variable type; for the purposes of this rule, the partial view of a |
| 3587 |
type is presumed to have nonvisible components whose default initialization |
| 3588 |
evaluates such an @nt{allocator};]} |
| 3589 |
|
| 3590 |
@begin{Reason} |
| 3591 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0004-1]} |
| 3592 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Such an @nt{allocator} would |
| 3593 |
provide a backdoor way to get a global variable into a pure unit, so it is |
| 3594 |
prohibited. Most such @nt{allocator}s are illegal anyway, as their type is |
| 3595 |
required to have Storage_Size = 0 (see the next two rules). But access |
| 3596 |
parameters and access discriminants don't necessarily disallow @nt{allocator}s. |
| 3597 |
However, a call is also illegal here (by the preelaboration rules), so access |
| 3598 |
parameters cannot cause trouble. So this rule is really about prohibiting |
| 3599 |
allocators in discriminant constraints:]} |
| 3600 |
|
| 3601 |
@begin{Example} |
| 3602 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3603 |
@ChgAdded{Version=[3],Text=[@key[type] Rec (Acc : @key[access] Integer) @key[is record] |
| 3604 |
C : Character; |
| 3605 |
@key[end record];]} |
| 3606 |
|
| 3607 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3608 |
@ChgAdded{Version=[3],Text=[Not_Const : @key[constant] Rec (Acc => @key[new] Integer'(2)); -- @RI{Illegal in a pure unit}.]} |
| 3609 |
@end{Example} |
| 3610 |
|
| 3611 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3612 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0004-1]} |
| 3613 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[The second half of the],Old=[This]} |
| 3614 |
rule is needed because aggregates can specify the default initialization |
| 3615 |
of a private type or extension using <> or the ancestor subtype of an |
| 3616 |
extension aggregate. The |
| 3617 |
subtype of a component could use an @nt{allocator} to initialize an access |
| 3618 |
discriminant; the type still could have a pragma Preelaborable_Initialization |
| 3619 |
given. Ada 95 did not allow such private types to have preelaborable |
| 3620 |
initialization, so such a default initialization could not have occurred. |
| 3621 |
Thus this rule is not incompatible with Ada 95.]} |
| 3622 |
@end{Reason} |
| 3623 |
|
| 3624 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3625 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]} |
| 3626 |
@ChgAdded{Version=[2],Text=[the elaboration of the declaration of a |
| 3627 |
@Chg{Version=[3],New=[nonderived ],Old=[]}named |
| 3628 |
access-to-variable type unless the Storage_Size of the type |
| 3629 |
has been specified by a static expression with value zero or |
| 3630 |
is defined by the language to be zero;]} |
| 3631 |
|
| 3632 |
@begin{Discussion} |
| 3633 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3634 |
@ChgAdded{Version=[2],Text=[A remote access-to-class-wide type |
| 3635 |
(see @RefSecNum{Remote Types Library Units}) has its Storage_Size defined to |
| 3636 |
be zero.]} |
| 3637 |
@end{Discussion} |
| 3638 |
@begin{Reason} |
| 3639 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]} |
| 3640 |
@ChgAdded{Version=[2],Text=[We disallow most named access-to-object types |
| 3641 |
because an @nt{allocator} has a side effect; the pool constitutes variable |
| 3642 |
data. We allow access-to-subprogram types because they |
| 3643 |
don't have @nt{allocator}s. We even allow named access-to-object types if |
| 3644 |
they have an empty predefined pool (they can't have a user-defined pool as |
| 3645 |
System.Storage_Pools is not pure). In this case, most attempts to use an |
| 3646 |
@nt{allocator} are illegal, and any others (in a generic body) will raise |
| 3647 |
Storage_Error.]} |
| 3648 |
@end{Reason} |
| 3649 |
|
| 3650 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3651 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]} |
| 3652 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0232-1]} |
| 3653 |
@ChgAdded{Version=[2],Text=[the elaboration of the declaration of a |
| 3654 |
@Chg{Version=[3],New=[nonderived ],Old=[]}named |
| 3655 |
access-to-constant type for which the Storage_Size has been specified by an |
| 3656 |
expression other than a static expression with value |
| 3657 |
zero@Chg{Version=[5],New=[;],Old=[.]}]} |
| 3658 |
|
| 3659 |
@begin{Discussion} |
| 3660 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3661 |
@ChgAdded{Version=[2],Text=[We allow access-to-constant types so long as |
| 3662 |
there is no user-specified nonzero Storage_Size; if there were a |
| 3663 |
user-specified nonzero Storage_Size restricting the size of the storage |
| 3664 |
pool, allocators would be problematic since the package is supposedly |
| 3665 |
@lquote@;stateless@rquote, and the allocated size count for the storage pool |
| 3666 |
would represent state.]} |
| 3667 |
@end{Discussion} |
| 3668 |
|
| 3669 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0232-1]} |
| 3670 |
@ChgAdded{Version=[5],Text=[the elaboration of any program unit that is not |
| 3671 |
pure.]} |
| 3672 |
|
| 3673 |
@end{Itemize} |
| 3674 |
|
| 3675 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0232-1]} |
| 3676 |
@ChgAdded{Version=[5],Text=[A generic declaration is pure unless every |
| 3677 |
instance would perform one of the above actions.]} |
| 3678 |
|
| 3679 |
@begin{Ramification} |
| 3680 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0232-1]} |
| 3681 |
@ChgAdded{Version=[5],Text=[A generic declaration is pure unless |
| 3682 |
there is no instance that could be declared pure. For instance, |
| 3683 |
a generic package declaration that directly contains a variable declaration |
| 3684 |
is not pure (and thus would be illegal if pragma Pure is applied to it).]} |
| 3685 |
@end{Ramification} |
| 3686 |
|
| 3687 |
|
| 3688 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0035-1]} |
| 3689 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0232-1]}@Comment{Just to change the paragraph number} |
| 3690 |
@ChgAdded{Version=[3],Text=[A generic body is pure only if elaboration of a |
| 3691 |
corresponding instance body would not perform any such actions presuming any |
| 3692 |
composite formal types have nonvisible components whose default initialization |
| 3693 |
evaluates an @nt{allocator} of an access-to-variable type.]} |
| 3694 |
|
| 3695 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00366-01]} |
| 3696 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0232-1]}@Comment{Just to change the paragraph number} |
| 3697 |
@ChgAdded{Version=[2],Text=[The Storage_Size for an anonymous |
| 3698 |
access-to-variable type declared at library level in a library unit that is |
| 3699 |
declared pure is defined to be zero.]} |
| 3700 |
|
| 3701 |
@begin{Ramification} |
| 3702 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3703 |
@ChgAdded{Version=[2],Text=[This makes @nt{allocator}s illegal for such types |
| 3704 |
(see @RefSecNum{Allocators}), making a storage pool unnecessary for these |
| 3705 |
types. A storage pool would represent state.]} |
| 3706 |
|
| 3707 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3708 |
@ChgAdded{Version=[2],Text=[Note that access discriminants and access |
| 3709 |
parameters are never library-level, even when they are declared in a |
| 3710 |
type or subprogram declared at library-level. That's because they have their |
| 3711 |
own special accessibility rules (see @RefSecNum{Operations of Access Types}).]} |
| 3712 |
@end{Ramification} |
| 3713 |
|
| 3714 |
@end{StaticSem} |
| 3715 |
|
| 3716 |
|
| 3717 |
@begin{Legality} |
| 3718 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00366-01]} |
| 3719 |
@ChgDeleted{Version=[2],Text=[@Defn{pure} |
| 3720 |
A @i{pure} @nt{library_item} is a preelaborable @nt{library_item} |
| 3721 |
that does not contain the declaration of any |
| 3722 |
variable or named access within a |
| 3723 |
subprogram, generic |
| 3724 |
subprogram, |
| 3725 |
task unit, or protected unit.]} |
| 3726 |
|
| 3727 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]} |
| 3728 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0034-1],ARef=[AI05-0035-1],ARef=[AI05-0243-1]} |
| 3729 |
@Defn{declared pure} |
| 3730 |
A @nt{pragma} Pure is used to @Chg{Version=[3],New=[specify],Old=[declare]} |
| 3731 |
that a library unit is @Chg{Version=[3],New=[@i{declared pure}, namely |
| 3732 |
that the Pure aspect@AspectDefn{Pure} of the library unit is True; all |
| 3733 |
compilation units of the library unit are declared ],Old=[]}pure. |
| 3734 |
@Chg{Version=[3],New=[In addition, the limited view |
| 3735 |
of any library package is declared pure. The declaration and |
| 3736 |
body of a declared pure library unit, and all subunits that are |
| 3737 |
elaborated as part of elaborating the library unit, shall be pure. |
| 3738 |
All],Old=[If a @nt{pragma} Pure applies to a library unit, |
| 3739 |
then its]} compilation units @Chg{Version=[3],New=[of a declared pure |
| 3740 |
library unit],Old=[shall be pure, and they]} shall depend semantically |
| 3741 |
only on @Chg{Version=[3],New=[],Old=[compilation units of other library units |
| 3742 |
that are ]}declared pure@Chg{Version=[3],New=[ @nt{library_item}s], |
| 3743 |
Old=[]}.@Chg{Version=[3],New=[ @PDefn{generic contract issue} |
| 3744 |
In addition to the places where @LegalityTitle normally apply |
| 3745 |
(see @RefSecNum{Generic Instantiation}), these rules also |
| 3746 |
apply in the private part of an instance of a generic unit.], |
| 3747 |
Old=[]}@Chg{Version=[2],New=[ Furthermore, the full view of any |
| 3748 |
partial view declared in the visible part of @Chg{Version=[3],New=[a declared |
| 3749 |
pure],Old=[the]} library unit that has |
| 3750 |
any available stream attributes shall support external streaming |
| 3751 |
(see @RefSecNum{Stream-Oriented Attributes}).],Old=[]} |
| 3752 |
@begin{Honest} |
| 3753 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0243-1]}@ChgNote{This is now described normatively} |
| 3754 |
@ChgDeleted{Version=[3],Text=[A @i{declared-pure} library unit is one to |
| 3755 |
which a @nt{pragma} Pure applies. |
| 3756 |
Its declaration and body are also said to be declared pure.]} |
| 3757 |
@end{Honest} |
| 3758 |
@begin{Discussion} |
| 3759 |
A declared-pure package is useful for defining types to be shared |
| 3760 |
between partitions with no common address space. |
| 3761 |
@end{Discussion} |
| 3762 |
@begin{Reason} |
| 3763 |
Note that generic packages are not mentioned |
| 3764 |
in the list of things that can contain variable declarations. |
| 3765 |
Note that the Ada 95 rules for deferred constants make them |
| 3766 |
allowable in library units that are declared pure; |
| 3767 |
that isn't true of Ada 83's deferred constants. |
| 3768 |
@end{Reason} |
| 3769 |
@begin{Ramification} |
| 3770 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]} |
| 3771 |
Anonymous access types |
| 3772 |
@Chg{Version=[2],New=[],Old=[(that is, access discriminants and |
| 3773 |
access parameters) ]}are allowed. |
| 3774 |
|
| 3775 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0243-1]} |
| 3776 |
@ChgAdded{Version=[3],Text=[A limited view is not a library unit, so any rule |
| 3777 |
that starts @ldquote@;declared pure library unit@rdquote does not apply to a |
| 3778 |
limited view. In particular, the 3rd and last sentences never apply to limited |
| 3779 |
views. However, a limited view is a @nt{library_item}, so rules that discuss |
| 3780 |
@ldquote@;declared pure @nt{library_item}s@rdquote do include limited views.]} |
| 3781 |
@end{Ramification} |
| 3782 |
@begin{Reason} |
| 3783 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]} |
| 3784 |
@Chg{Version=[2],New=[Ada 95 didn't allow any access types as], |
| 3785 |
Old=[The primary reason for disallowing named |
| 3786 |
access types is that an @nt{allocator} has a side effect; |
| 3787 |
the pool constitutes variable data. We considered somehow allowing |
| 3788 |
@nt{allocator}-less access types. However,]} these |
| 3789 |
(including access-to-subprogram types) |
| 3790 |
@Chg{Version=[2],New=[],Old=[would ]}cause trouble |
| 3791 |
for @RefSec{Distributed Systems}, because such types @Chg{Version=[2],New=[], |
| 3792 |
Old=[would ]} allow access values in a shared passive |
| 3793 |
partition to designate objects in an active partition, |
| 3794 |
thus allowing inter-address space references.@Chg{Version=[2],New=[ We decided |
| 3795 |
to disallow such uses in the relatively rare cases where they cause problems, |
| 3796 |
rather than making life harder for the majority of users. Types declared |
| 3797 |
in a pure package can be used in remote operations only if they are externally |
| 3798 |
streamable. That simply means that there is a means to transport values of the |
| 3799 |
type; that's automatically true for nonlimited types that don't have an |
| 3800 |
access part. The only tricky part about this is to avoid privacy leakage; that |
| 3801 |
was handled by ensuring that any private types (and private |
| 3802 |
extensions) declared in a pure package that have available stream attributes |
| 3803 |
(which include all nonlimited types by definition) have to be externally |
| 3804 |
streamable.], |
| 3805 |
Old=[Furthermore, a named access-to-object type without a pool would be a new |
| 3806 |
concept, adding complexity from the user's point of view. Finally, the |
| 3807 |
prevention of @nt{allocator}s would have to be |
| 3808 |
a runtime check, in order to avoid violations of the generic contract |
| 3809 |
model.]} |
| 3810 |
@end{Reason} |
| 3811 |
|
| 3812 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pure], |
| 3813 |
Text=[@ChgAdded{Version=[3],Text=[Side effects are avoided in the |
| 3814 |
subprograms of a given package.]}]} |
| 3815 |
|
| 3816 |
@end{Legality} |
| 3817 |
|
| 3818 |
@begin{Erron} |
| 3819 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0076-1]} |
| 3820 |
@ChgAdded{Version=[4],Text=[Execution is erroneous if some operation (other |
| 3821 |
than the initialization or finalization of the object) modifies the value of a |
| 3822 |
constant object declared at library-level in a pure package.]} |
| 3823 |
|
| 3824 |
@begin{Discussion} |
| 3825 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 3826 |
@ChgAdded{Version=[4],Text=[This could be accomplished via a |
| 3827 |
self-referencing pointer or via squirrelling a writable pointer to a |
| 3828 |
controlled object.]} |
| 3829 |
@end{Discussion} |
| 3830 |
@end{Erron} |
| 3831 |
|
| 3832 |
@begin{ImplPerm} |
| 3833 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]} |
| 3834 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0219-1]} |
| 3835 |
If a library unit is declared pure, then the implementation |
| 3836 |
is permitted to omit a call on a library-level |
| 3837 |
subprogram of the library unit if the |
| 3838 |
results are not needed after the call. @Chg{Version=[2],New=[In addition, |
| 3839 |
the implementation],Old=[Similarly, it]} may omit @Chg{Version=[2],New=[], |
| 3840 |
Old=[such ]}a call@Chg{Version=[2],New=[ on such a subprogram],Old=[]} and |
| 3841 |
simply reuse the results produced by an earlier call on |
| 3842 |
the same subprogram, provided that none of the |
| 3843 |
parameters @Chg{Version=[2],New=[nor any object accessible via access |
| 3844 |
values from the parameters ],Old=[]}@Chg{Version=[3],New=[have any part that |
| 3845 |
is of a type whose full type is an immutably],Old=[are of |
| 3846 |
a]} limited type, and the addresses and values of all by-reference |
| 3847 |
actual parameters, @Chg{Version=[2],New=[],Old=[and ]}the values of all |
| 3848 |
by-copy-in actual parameters, @Chg{Version=[2],New=[and the values of all |
| 3849 |
objects accessible via access values from the parameters, ],Old=[]}are |
| 3850 |
the same as they were at the earlier call. |
| 3851 |
@Redundant[This permission applies even if the subprogram |
| 3852 |
produces other side effects when called.] |
| 3853 |
@begin{Discussion} |
| 3854 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]} |
| 3855 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1],ARef=[AI05-0299-1]} |
| 3856 |
A declared-pure @nt{library_item} has no variable state. |
| 3857 |
Hence, a call on one of its (nonnested) subprograms cannot |
| 3858 |
@Chg{Version=[2],New=[normally],Old=[@lquotes@;normally@rquotes]} |
| 3859 |
have side effects. @Chg{Version=[3],New=[Side effects are still possible |
| 3860 |
via dispatching calls and via indirect calls through access-to-subprogram |
| 3861 |
values. Other mechanisms that might be used to modify variable state |
| 3862 |
include],Old=[The only possible side effects from such a call would be |
| 3863 |
through]} |
| 3864 |
machine code insertions,@Chg{Version=[2],New=[ imported subprograms, |
| 3865 |
@Chg{Version=[3],New=[ and ],Old=[]}],Old=[]}unchecked conversion to an access type declared within the |
| 3866 |
subprogram@Chg{Version=[3],New=[; this list is not exhaustive],Old=[, and |
| 3867 |
similar features]}.@Chg{Version=[3],New=[ Thus, the permissions described |
| 3868 |
in this subclause may apply to a subprogram whose execution has |
| 3869 |
side effects.],Old=[]} The compiler may omit a call to such a subprogram |
| 3870 |
even if @Chg{Version=[3],New=[],Old=[such]} side effects exist, so the |
| 3871 |
writer of such a subprogram has to keep this in mind. |
| 3872 |
@end{Discussion} |
| 3873 |
|
| 3874 |
@end{ImplPerm} |
| 3875 |
|
| 3876 |
@begin{Syntax} |
| 3877 |
@begin{SyntaxText} |
| 3878 |
@Leading@Keepnext@;The form of a @nt{pragma} Elaborate, Elaborate_All, or |
| 3879 |
Elaborate_Body is as follows: |
| 3880 |
@end{SyntaxText} |
| 3881 |
|
| 3882 |
@PragmaSyn`@key{pragma} @prag(Elaborate)(@SynI{library_unit_}@Syn2{name}{, @SynI{library_unit_}@Syn2{name}});' |
| 3883 |
|
| 3884 |
@PragmaSyn`@key{pragma} @prag(Elaborate_All)(@SynI{library_unit_}@Syn2{name}{, @SynI{library_unit_}@Syn2{name}});' |
| 3885 |
|
| 3886 |
@PragmaSyn`@key{pragma} @prag(Elaborate_Body)[(@SynI{library_unit_}@Syn2{name})];' |
| 3887 |
|
| 3888 |
@begin{SyntaxText} |
| 3889 |
A @nt{pragma} Elaborate or Elaborate_All is only allowed within a |
| 3890 |
@nt{context_clause}. |
| 3891 |
@begin{Ramification} |
| 3892 |
@lquotes@;Within a @nt{context_clause}@rquotes@; allows it to be the last |
| 3893 |
item in the @nt{context_clause}. |
| 3894 |
It can't be first, because the @nt{name} has to denote something |
| 3895 |
mentioned earlier. |
| 3896 |
@end{Ramification} |
| 3897 |
|
| 3898 |
@PDefn2{Term=[library unit pragma], Sec=(Elaborate_Body)} |
| 3899 |
@PDefn2{Term=[pragma, library unit], Sec=(Elaborate_Body)} |
| 3900 |
A @nt{pragma} Elaborate_Body is a library unit pragma. |
| 3901 |
@end{SyntaxText} |
| 3902 |
@begin{Discussion} |
| 3903 |
Hence, a @nt{pragma} Elaborate or Elaborate_All is not |
| 3904 |
elaborated, not that it makes any practical difference. |
| 3905 |
|
| 3906 |
Note that a @nt{pragma} Elaborate or Elaborate_All is neither a program unit |
| 3907 |
pragma, nor a library unit pragma. |
| 3908 |
|
| 3909 |
@end{Discussion} |
| 3910 |
@end{Syntax} |
| 3911 |
|
| 3912 |
@begin{Legality} |
| 3913 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 3914 |
@PDefn2{Term=[requires a completion], Sec=(declaration to which a @nt{pragma} Elaborate_Body applies)} |
| 3915 |
If @Chg{Version=[3],New=[the aspect],Old=[a @nt{pragma}]} Elaborate_Body |
| 3916 |
@Chg{Version=[3],New=[is True for],Old=[applies to]} a |
| 3917 |
declaration@Chg{Version=[3],New=[ @Redundant[(including when @nt{pragma} |
| 3918 |
Elaborate_Body applies)]],Old=[]}, |
| 3919 |
then the declaration requires a completion @Redundant[(a |
| 3920 |
body)].@Chg{Version=[3],New=[@PDefn2{Term=[requires a completion], |
| 3921 |
Sec=(declaration for which aspect Elaborate_Body is True)}],Old=[]} |
| 3922 |
|
| 3923 |
@begin{TheProof} |
| 3924 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 3925 |
@ChgAdded{Version=[3],Text=[@nt{Pragma} Elaborate_Body sets the |
| 3926 |
aspect (see below).]} |
| 3927 |
@end{TheProof} |
| 3928 |
|
| 3929 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]} |
| 3930 |
@ChgAdded{Version=[2],Text=[The @SynI{library_unit_}@nt{name} of a |
| 3931 |
@nt{pragma} Elaborate or Elaborate_All shall denote a nonlimited view |
| 3932 |
of a library unit.]} |
| 3933 |
@begin{Reason} |
| 3934 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3935 |
@ChgAdded{Version=[2],Text=[These @nt{pragma}s are intended to prevent |
| 3936 |
elaboration check failures. But a limited view does not make anything visible |
| 3937 |
that has an elaboration check, so the @nt{pragma}s cannot do anything useful. |
| 3938 |
Moreover, the @nt{pragma}s would probably reintroduce |
| 3939 |
the circularity that the @nt{limited_with_clause} was intended to break. |
| 3940 |
So we make such uses illegal.]} |
| 3941 |
@end{Reason} |
| 3942 |
|
| 3943 |
@end{Legality} |
| 3944 |
|
| 3945 |
@begin{StaticSem} |
| 3946 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 3947 |
@redundant[A @nt{pragma} Elaborate specifies that the body of the named library |
| 3948 |
unit is elaborated before the current @nt{library_item}. |
| 3949 |
A @nt{pragma} Elaborate_All specifies that each @nt{library_item} that is |
| 3950 |
needed by the named library unit declaration |
| 3951 |
is elaborated before the current @nt{library_item}.@Chg{Version=[3],New=[],Old=[ |
| 3952 |
A @nt{pragma} Elaborate_Body specifies that the body |
| 3953 |
of the library unit is elaborated immediately after its declaration.]}] |
| 3954 |
|
| 3955 |
@begin{TheProof} |
| 3956 |
The official statement of the semantics of these @nt{pragma}s is given in |
| 3957 |
@RefSecNum{Program Execution}. |
| 3958 |
@end{TheProof} |
| 3959 |
|
| 3960 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]} |
| 3961 |
@ChgAdded{Version=[3],Text=[A @nt{pragma} Elaborate_Body sets the Elaborate_Body |
| 3962 |
representation aspect of the library unit to which it applies to the value True. |
| 3963 |
@Redundant[If the Elaborate_Body aspect of a library unit is True, the body of the library |
| 3964 |
unit is elaborated immediately after its declaration.@AspectDefn{Elaborate_Body}]]} |
| 3965 |
|
| 3966 |
@begin{TheProof} |
| 3967 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3968 |
@ChgAdded{Version=[3],Text=[The official statement of the semantics of this |
| 3969 |
aspect is given in @RefSecNum{Program Execution}.]} |
| 3970 |
@end{TheProof} |
| 3971 |
@begin{ImplNote} |
| 3972 |
The presence of a @nt{pragma} Elaborate_Body simplifies the removal of |
| 3973 |
unnecessary Elaboration_Checks. |
| 3974 |
For a subprogram declared immediately within a library unit to which |
| 3975 |
a @nt{pragma} Elaborate_Body applies, the only calls that can fail the |
| 3976 |
Elaboration_Check are those that occur in the library unit itself, |
| 3977 |
between the declaration and body of the called subprogram; |
| 3978 |
if there are no such calls |
| 3979 |
(which can easily be detected at compile time |
| 3980 |
if there are no @ntf{stub}s), |
| 3981 |
then no Elaboration_Checks are needed for that subprogram. |
| 3982 |
The same is true for Elaboration_Checks on task activations and |
| 3983 |
instantiations, and for library subprograms and generic units. |
| 3984 |
@end{ImplNote} |
| 3985 |
@begin{Ramification} |
| 3986 |
The fact that the unit of elaboration is the @nt{library_item} |
| 3987 |
means that if a @nt{subprogram_body} is not a completion, it is |
| 3988 |
impossible for any @nt{library_item} to be elaborated between the |
| 3989 |
declaration and the body of such a subprogram. |
| 3990 |
Therefore, it is impossible for a call to such a subprogram to fail its |
| 3991 |
Elaboration_Check. |
| 3992 |
@end{Ramification} |
| 3993 |
@begin{Discussion} |
| 3994 |
The visibility rules imply that |
| 3995 |
each @i{library_unit_}@nt{name} of a @nt{pragma} Elaborate |
| 3996 |
or Elaborate_All has to denote a library unit mentioned by a |
| 3997 |
previous @nt{with_clause} of the same @nt{context_clause}. |
| 3998 |
@end{Discussion} |
| 3999 |
|
| 4000 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Elaborate_Body], |
| 4001 |
Text=[@ChgAdded{Version=[3],Text=[A given package must have a body, and that |
| 4002 |
body is elaborated immediately after the declaration.]}]} |
| 4003 |
|
| 4004 |
@end{StaticSem} |
| 4005 |
|
| 4006 |
@begin{Notes} |
| 4007 |
A preelaborated library unit is allowed to have nonpreelaborable |
| 4008 |
children. |
| 4009 |
@begin{Ramification} |
| 4010 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]} |
| 4011 |
But @Chg{New=[generally ], Old=[]}not nonpreelaborated subunits. |
| 4012 |
@Chg{New=[(Nonpreelaborated subunits of subprograms are allowed as |
| 4013 |
discussed above.)], Old=[]} |
| 4014 |
@end{Ramification} |
| 4015 |
|
| 4016 |
A library unit that is declared pure is allowed to have impure |
| 4017 |
children. |
| 4018 |
@begin{Ramification} |
| 4019 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]} |
| 4020 |
But @Chg{New=[generally ], Old=[]}not impure subunits. |
| 4021 |
@Chg{New=[(Impure subunits of subprograms are allowed as discussed above.)], |
| 4022 |
Old=[]} |
| 4023 |
@end{Ramification} |
| 4024 |
@begin{Ramification} |
| 4025 |
Pragma Elaborate is mainly for closely related library units, |
| 4026 |
such as when two package bodies 'with' each other's declarations. |
| 4027 |
In such cases, Elaborate_All sometimes won't work. |
| 4028 |
@end{Ramification} |
| 4029 |
@end{Notes} |
| 4030 |
|
| 4031 |
@begin{Extend83} |
| 4032 |
@Defn{extensions to Ada 83} |
| 4033 |
The concepts of preelaborability |
| 4034 |
and purity are new to Ada 95. |
| 4035 |
The Elaborate_All, Elaborate_Body, Preelaborate, |
| 4036 |
and Pure @nt{pragma}s are new to Ada 95. |
| 4037 |
|
| 4038 |
Pragmas Elaborate are allowed to be mixed in with the other |
| 4039 |
things in the @nt{context_clause} @em in Ada 83, they were |
| 4040 |
required to appear last. |
| 4041 |
@end{Extend83} |
| 4042 |
|
| 4043 |
@begin{Incompatible95} |
| 4044 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]} |
| 4045 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 4046 |
The requirement that a partial view with available stream attributes |
| 4047 |
be externally streamable can cause an incompatibility in rare cases. |
| 4048 |
If there is a limited tagged |
| 4049 |
type declared in a pure package with available attributes, and that |
| 4050 |
type is used to declare a private extension in another pure package, |
| 4051 |
and the full type for the private extension has a component of an |
| 4052 |
explicitly limited record type, a protected type, or a type with |
| 4053 |
access discriminants, then the stream attributes will have to be |
| 4054 |
user-specified in the visible part of the package. That is not a requirement |
| 4055 |
for Ada 95, but this combination seems very unlikely in pure packages. |
| 4056 |
Note that this cannot be an incompatibility for a nonlimited type, |
| 4057 |
as all of the types that are allowed in Ada 95 that would require |
| 4058 |
explicitly defined stream attributes are limited (and thus cannot be used |
| 4059 |
as components in a nonlimited type).]} |
| 4060 |
|
| 4061 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00403-01]} |
| 4062 |
@ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Added wording |
| 4063 |
to cover missing cases for preelaborated generic units. This is |
| 4064 |
incompatible as a preelaborated unit could have used a formal |
| 4065 |
object to initialize a library-level object; that isn't allowed in Ada 2005. But such a unit wouldn't really |
| 4066 |
be preelaborable, and Ada 95 compilers can reject such units (as this |
| 4067 |
is a Binding Interpretation), so such units should be very rare.]} |
| 4068 |
@end{Incompatible95} |
| 4069 |
|
| 4070 |
@begin{Extend95} |
| 4071 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]} |
| 4072 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 4073 |
@b[Amendment Correction:] The concept of preelaborable initialization and |
| 4074 |
@nt{pragma} Preelaborable_Initialization are new. These allow more types |
| 4075 |
of objects to be created in preelaborable units, and fix holes in the |
| 4076 |
old rules.]} |
| 4077 |
|
| 4078 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]} |
| 4079 |
@ChgAdded{Version=[2],Text=[Access-to-subprogram types and access-to-object |
| 4080 |
types with a Storage_Size of 0 are allowed in pure units. The permission |
| 4081 |
to omit calls was adjusted accordingly (which also fixes a hole in Ada 95, as |
| 4082 |
access parameters are allowed, and changes in the values accessed by them |
| 4083 |
must be taken into account).]} |
| 4084 |
@end{Extend95} |
| 4085 |
|
| 4086 |
@begin{DiffWord95} |
| 4087 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00002-01]} |
| 4088 |
@ChgAdded{Version=[2],Text=[@B<Corrigendum:> The wording was changed so that |
| 4089 |
subunits of a preelaborated subprogram are also preelaborated.]} |
| 4090 |
|
| 4091 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]} |
| 4092 |
@ChgAdded{Version=[2],Text=[Disallowed pragma Elaborate and Elaborate_All |
| 4093 |
for packages that are mentioned in a @nt{limited_with_clause}.]} |
| 4094 |
@end{DiffWord95} |
| 4095 |
|
| 4096 |
@begin{Incompatible2005} |
| 4097 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1]} |
| 4098 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@B<Correction:> |
| 4099 |
Corrected a serious |
| 4100 |
unintended incompatibility with Ada 95 in the new preelaboration wording |
| 4101 |
@em explicit initialization of objects of types that don't have |
| 4102 |
preelaborable initialization was not allowed. Ada 2012 switches |
| 4103 |
back to the Ada 95 rule in these cases. This is unlikely to |
| 4104 |
occur in practice, as it is unlikely that a compiler would have |
| 4105 |
implemented the more restrictive rule (it would fail many ACATS tests |
| 4106 |
if it did).]} |
| 4107 |
|
| 4108 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]} |
| 4109 |
@ChgAdded{Version=[3],Text=[@B<Correction:> Added an assume-the-worst |
| 4110 |
rule for generic bodies (else they would never be checked for purity) |
| 4111 |
and added the boilerplate so that the entire generic specification is |
| 4112 |
rechecked. Also fixed wording to have consistent handling for subunits |
| 4113 |
for Pure and Preelaborate. An Ada 95 program could have depended on |
| 4114 |
marking a generic pure that was not really pure, although this |
| 4115 |
would defeat the purpose of the categorization and likely cause |
| 4116 |
problems with distributed programs.]} |
| 4117 |
@end{Incompatible2005} |
| 4118 |
|
| 4119 |
@begin{Extend2005} |
| 4120 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]} |
| 4121 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@B<Correction:> |
| 4122 |
Adjusted wording so that a subunit can be pure (it is not a |
| 4123 |
@nt<library_item>, but it is a compilation unit).]} |
| 4124 |
|
| 4125 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]} |
| 4126 |
@ChgAdded{Version=[3],Text=[@B<Correction:> Adjusted wording so |
| 4127 |
that the rules for access types only apply to nonderived types |
| 4128 |
(derived types share their storage pool with their parent, so if |
| 4129 |
the parent access type is legal, so is any derived type.)]} |
| 4130 |
|
| 4131 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 4132 |
@ChgAdded{Version=[3],Text=[Elaborate_Body is now an aspect, |
| 4133 |
so it can be specified by an @nt{aspect_specification} @em |
| 4134 |
although the pragma is still preferred by the Standard.]} |
| 4135 |
|
| 4136 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0243-1]} |
| 4137 |
@ChgAdded{Version=[3],Text=[Pure and Preelaborate are now aspects, |
| 4138 |
so they can be specified by an @nt{aspect_specification} @em |
| 4139 |
although the pragmas are still preferred by the Standard.]} |
| 4140 |
@end{Extend2005} |
| 4141 |
|
| 4142 |
@begin{DiffWord2005} |
| 4143 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0034-1]} |
| 4144 |
@ChgAdded{Version=[3],Text=[@B<Correction:> Added wording so that |
| 4145 |
a limited view is always treated as pure, no matter what categorization |
| 4146 |
is used for the originating unit. This was undefined in Ada 2005.]} |
| 4147 |
|
| 4148 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1],ARef=[AI05-0221-1]} |
| 4149 |
@ChgAdded{Version=[3],Text=[@B<Correction:> Fixed minor issues with |
| 4150 |
preelaborable initialization (PI): null Initialize procedures do not make |
| 4151 |
a type non-PI; formal types with pragma PI can be assumed to have PI; |
| 4152 |
formal extensions are assumed to not have PI; all composite types |
| 4153 |
can have pragma PI (so that the possibility of hidden Initialize routines |
| 4154 |
can be handled); added discriminants of a derived type are not considered |
| 4155 |
in calculating PI.]} |
| 4156 |
|
| 4157 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0219-1]} |
| 4158 |
@ChgAdded{Version=[3],Text=[@B<Correction:> Clarified that the implementation |
| 4159 |
permission to omit pure subprogram calls does not apply if any part of the |
| 4160 |
parameters or any designated object has a part that is immutably limited. |
| 4161 |
The old wording just said "limited type", which can change via visibility |
| 4162 |
and thus isn't appropriate for dynamic semantics permissions.]} |
| 4163 |
@end{DiffWord2005} |
| 4164 |
|
| 4165 |
@begin{Incompatible2012} |
| 4166 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0232-1]} |
| 4167 |
@ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@B<Correction:> |
| 4168 |
Added a rule that a generic declaration is not pure if no instance could be |
| 4169 |
pure (for instance, because the generic declaration would elaborates a |
| 4170 |
variable.) This was legal in Ada 2012, but of course no instance could have |
| 4171 |
been declared pure. A similar rule (with a similar effect) was added for |
| 4172 |
preelaborable generic declarations.]} |
| 4173 |
@end{Incompatible2012} |
| 4174 |
|
| 4175 |
@begin{Extend2012} |
| 4176 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0175-1]} |
| 4177 |
@ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Added some intrinsic |
| 4178 |
conversion functions to those allowed to be called during the elaboration of |
| 4179 |
a preelaborated unit. This is necessary to allow a portable Address aspect |
| 4180 |
in a preelaborated unit, important on small embedded systems.]} |
| 4181 |
@end{Extend2012} |
| 4182 |
|
| 4183 |
@begin{DiffWord2012} |
| 4184 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0076-1]} |
| 4185 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Explicitly stated that modifying |
| 4186 |
a library-level constant in a pure package is erroneous. We don't document |
| 4187 |
this as inconsistent as implementations certainly can still do whatever they |
| 4188 |
were previously doing (no change is required); moreover, this case (and many |
| 4189 |
more) were erroneous in Ada 2005 and before, so we're just restoring the |
| 4190 |
previous semantics.]} |
| 4191 |
|
| 4192 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0232-1]} |
| 4193 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Explicitly stated that |
| 4194 |
the pure and preelaborate rules are recursive; that is, they apply to the |
| 4195 |
contents of nested packages and generic packages.]} |
| 4196 |
@end{DiffWord2012} |
| 4197 |
|