1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Declarative Region</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-8.html">Previous</A> <A HREF="AA-8-2.html">Next</A></P>
<HR>
<H1> 8.1 Declarative Region</H1>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I3320"></A>For
each of the following constructs, there is a portion of the program text
called its <I>declarative region</I>, [within which nested declarations
can occur]: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>any declaration, other than that of an enumeration type,
that is not a completion [of a previous declaration];</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">block_statement</FONT>;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">loop_statement</FONT>;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>an <FONT FACE="Arial, Helvetica">accept_statement</FONT>;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>an <FONT FACE="Arial, Helvetica">exception_handler</FONT>.
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Wide" Style="margin-bottom: 0.4em"> The declarative region
includes the text of the construct together with additional text determined
[(recursively)], as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If a declaration is included, so is its completion, if
any.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the declaration of a library unit [(including Standard
-- see <A HREF="AA-10-1-1.html">10.1.1</A>)] is included, so are the
declarations of any child units [(and their completions, by the previous
rule)]. The child declarations occur after the declaration.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If a <FONT FACE="Arial, Helvetica">body_stub</FONT> is
included, so is the corresponding <FONT FACE="Arial, Helvetica">subunit</FONT>.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If a <FONT FACE="Arial, Helvetica">type_declaration</FONT>
is included, then so is a corresponding <FONT FACE="Arial, Helvetica">record_representation_clause</FONT>,
if any. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This is so that
the <FONT FACE="Arial, Helvetica">component_declaration</FONT>s can be
directly visible in the <FONT FACE="Arial, Helvetica">record_representation_clause</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal"> The declarative region of a declaration is also
called the <I>declarative region</I> of any view or entity declared by
the declaration. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The constructs
that have declarative regions are the constructs that can have declarations
nested inside them. Nested declarations are declared in that declarative
region. The one exception is for enumeration literals; although they
are nested inside an enumeration type declaration, they behave as if
they were declared at the same level as the type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>A declarative
region does not include <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>s.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A declarative
region does not include <FONT FACE="Arial, Helvetica">context_clause</FONT>s.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3321"></A><A NAME="I3322"></A><A NAME="I3323"></A><A NAME="I3324"></A><A NAME="I3325"></A>A
declaration occurs <I>immediately within</I> a declarative region if
this region is the innermost declarative region that encloses the declaration
(the <I>immediately enclosing</I> declarative region), not counting the
declarative region (if any) associated with the declaration itself. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Don't confuse
the declarative region of a declaration with the declarative region in
which it immediately occurs. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal"> [<A NAME="I3326"></A> A declaration is <I>local</I>
to a declarative region if the declaration occurs immediately within
the declarative region.] [An entity is <I>local</I> to a declarative
region if the entity is declared by a declaration that is local to the
declarative region.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>"Occurs
immediately within" and "local to" are synonyms (when
referring to declarations).</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Thus, ``local to'' applies to
both declarations and entities, whereas ``occurs immediately within''
only applies to declarations. We use this term only informally; for cases
where precision is required, we use the term "occurs immediately
within", since it is less likely to cause confusion. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3327"></A>A declaration is <I>global</I>
to a declarative region if the declaration occurs immediately within
another declarative region that encloses the declarative region. An entity
is <I>global</I> to a declarative region if the entity is declared by
a declaration that is global to the declarative region. </DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>1 The children of a parent
library unit are inside the parent's declarative region, even though
they do not occur inside the parent's declaration or body. This implies
that one can use (for example) "P.Q" to refer to a child of
P whose defining name is Q, and that after "<B>use</B> P;"
Q can refer (directly) to that child.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>2 As explained above and
in <A HREF="AA-10-1-1.html">10.1.1</A>, ``<A HREF="AA-10-1-1.html">Compilation
Units - Library Units</A>'', all library units are descendants of Standard,
and so are contained in the declarative region of Standard. They are
<I>not</I> inside the declaration or body of Standard, but they <I>are</I>
inside its declarative region.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>3 For a declarative region
that comes in multiple parts, the text of the declarative region does
not contain any text that might appear between the parts. Thus, when
a portion of a declarative region is said to extend from one place to
another in the declarative region, the portion does not contain any text
that might appear between the parts of the declarative region. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>It is necessary
for the things that have a declarative region to include anything that
contains declarations (except for enumeration type declarations). This
includes any declaration that has a profile (that is, <FONT FACE="Arial, Helvetica">subprogram_declaration</FONT>,
<FONT FACE="Arial, Helvetica">subprogram_body</FONT>, <FONT FACE="Arial, Helvetica">entry_declaration</FONT>,
<FONT FACE="Arial, Helvetica">subprogram_renaming_declaration</FONT>,
<FONT FACE="Arial, Helvetica">formal_subprogram_declaration</FONT>, access-to-subprogram
<FONT FACE="Arial, Helvetica">type_declaration</FONT>), anything that
has a <FONT FACE="Arial, Helvetica">discriminant_part</FONT> (that is,
various kinds of <FONT FACE="Arial, Helvetica">type_declaration</FONT>),
anything that has a <FONT FACE="Arial, Helvetica">component_list</FONT>
(that is, record <FONT FACE="Arial, Helvetica">type_declaration</FONT>
and record extension <FONT FACE="Arial, Helvetica">type_declaration</FONT>),
and finally the declarations of task and protected units and packages.
</FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>18.b</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>It
was necessary to extend Ada 83's definition of declarative region to
take the following Ada 95 features into account: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.c</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Child library units.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.d</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Derived types/type extensions -- we need a declarative
region for inherited components and also for new components.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.e</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>All the kinds of types that allow discriminants.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.f</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Protected units.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.g</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Entries that have bodies instead of accept statements.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.h</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The <FONT FACE="Arial, Helvetica">choice_parameter_specification</FONT>
of an <FONT FACE="Arial, Helvetica">exception_handler</FONT>.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.i</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The formal parameters of access-to-subprogram types.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.j</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Renamings-as-body. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.k</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Discriminated and access-to-subprogram
type declarations need a declarative region. Enumeration type declarations
cannot have one, because you don't have to say "Color.Red"
to refer to the literal Red of Color. For other type declarations, it
doesn't really matter whether or not there is an associated declarative
region, so for simplicity, we give one to all types except enumeration
types.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.l</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We now say that an <FONT FACE="Arial, Helvetica">accept_statement</FONT>
has its own declarative region, rather than being part of the declarative
region of the <FONT FACE="Arial, Helvetica">entry_declaration</FONT>,
so that declarative regions are properly nested regions of text, so that
it makes sense to talk about "inner declarative regions," and
"...extends to the end of a declarative region." Inside an
<FONT FACE="Arial, Helvetica">accept_statement</FONT>, the <FONT FACE="Arial, Helvetica">name</FONT>
of one of the parameters denotes the <FONT FACE="Arial, Helvetica">parameter_specification</FONT>
of the <FONT FACE="Arial, Helvetica">accept_statement</FONT>, not that
of the <FONT FACE="Arial, Helvetica">entry_declaration</FONT>. If the
<FONT FACE="Arial, Helvetica">accept_statement</FONT> is nested within
a <FONT FACE="Arial, Helvetica">block_statement</FONT>, these <FONT FACE="Arial, Helvetica">parameter_specification</FONT>s
can hide declarations of the <FONT FACE="Arial, Helvetica">block_statement</FONT>.
The semantics of such cases was unclear in RM83. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.m</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>Unfortunately,
we have the same problem for the entry name itself -- it should denote
the <FONT FACE="Arial, Helvetica">accept_statement</FONT>, but <FONT FACE="Arial, Helvetica">accept_statement</FONT>s
are not declarations. They should be, and they should hide the entry
from all visibility within themselves. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.n</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that we can't generalize
this to <FONT FACE="Arial, Helvetica">entry_bodies</FONT>, or other bodies,
because the <FONT FACE="Arial, Helvetica">declarative_part</FONT> of
a body is not supposed to contain (explicit) homographs of things in
the declaration. It works for <FONT FACE="Arial, Helvetica">accept_statement</FONT>s
only because an <FONT FACE="Arial, Helvetica">accept_statement</FONT>
does not have a <FONT FACE="Arial, Helvetica">declarative_part</FONT>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.o</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>To avoid confusion, we use the
term ``local to'' only informally in Ada 95. Even RM83 used the term
incorrectly (see, for example, RM83-12.3(13)).</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.p</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In Ada 83, (root) library units
were inside Standard; it was not clear whether the declaration or body
of Standard was meant. In Ada 95, they are children of Standard, and
so occur immediately within Standard's declarative region, but not within
either the declaration or the body. (See RM83-8.6(2) and RM83-10.1.1(5).)
</FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-8.html">Previous</A> <A HREF="AA-8-2.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|