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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Object Renaming Declarations</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-5.html">Previous</A> <A HREF="AA-8-5-2.html">Next</A></P>
<HR>
<H1> 8.5.1 Object Renaming Declarations</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [An <FONT FACE="Arial, Helvetica">object_renaming_declaration</FONT>
is used to rename an object.] </DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">object_renaming_declaration<A NAME="I3401"></A>
::= </FONT><A NAME="I3402"></A><FONT FACE="Arial, Helvetica">defining_identifier</FONT> : <A NAME="I3403"></A><FONT FACE="Arial, Helvetica">subtype_mark</FONT> <B>renames</B> <I>object_</I><A NAME="I3404"></A><FONT FACE="Arial, Helvetica">name</FONT>;</DIV>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal"> The type of the <I>object_</I><FONT FACE="Arial, Helvetica">name</FONT>
shall resolve to the type determined by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Reason:
</B>A previous version of Ada 9X used the usual ``expected type'' wording:<BR>
``The expected type for the <I>object_</I><FONT FACE="Arial, Helvetica">name</FONT>
is that determined by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>.''<BR>
We changed it so that this would be illegal: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.b</FONT></DIV>
<DIV Class="SmallExamples"><TT>X: T;<BR>
Y: T'Class <B>renames</B> X; --<I> Illegal!</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.c</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>When
the above was legal, it was unclear whether Y was of type T or T'Class.
Note that we still allow this: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.d</FONT></DIV>
<DIV Class="SmallExamples"><TT>Z: T'Class := ...;<BR>
W: T <B>renames</B> F(Z);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>where F is a function with a controlling
parameter and result. This is admittedly a bit odd.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the matching rule for
generic formal parameters of mode <B>in out</B> was changed to keep it
consistent with the rule for renaming. That makes the rule different
for <B>in</B> vs. <B>in out</B>.</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal"> The renamed entity shall be an object.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0017">8652/0017</A></I>}
The renamed entity shall not be a subcomponent that depends on discriminants
of a variable whose nominal subtype is unconstrained, unless this subtype
is indefinite, or the variable is aliased. A <FONT FACE="Arial, Helvetica">slice</FONT>
of an array shall not be renamed if this restriction disallows renaming
of the array. <U>In addition to the places where Legality Rules normally
apply, these rules apply also in the private part of an instance of a
generic unit. These rules also apply for a renaming that appears in the
body of a generic unit, with the additional requirement that even if
the nominal subtype of the variable is indefinite, its type shall not
be a descendant of an untagged generic formal derived type.</U> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This prevents renaming
of subcomponents that might disappear, which might leave dangling references.
Similar restrictions exist for the Access attribute.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>{<I><A HREF="defect1.html#8652/0017">8652/0017</A></I>}
<U>The "recheck on instantiation" and "assume-the-worst
in the body" restrictions on generics are necessary to avoid renaming
of components which could disappear even when the nominal subtype would
prevent the problem:</U></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a.2/1</FONT></DIV>
<DIV Class="SmallExamples" Style="margin-bottom: 0.4em"><TT><U><B>type</B> T1 (D1 : Boolean) <B>is</B><BR>
<B>record</B><BR>
<B>case</B> D1 <B>is</B><BR>
<B>when</B> False =><BR>
C1 : Integer;<BR>
<B>when</B> True =><BR>
<B>null</B>;<BR>
<B>end</B> <B>case</B>;<BR>
<B>end</B> <B>record</B>;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a.3/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>generic</B><BR>
<B>type</B> F <B>is</B> <B>new</B> T1;<BR>
X : <B>in out</B> F;<BR>
<B>package</B> G <B>is</B><BR>
C1_Ren : Integer <B>renames</B> X.C1;<BR>
<B>end</B> G;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a.4/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>type</B> T2 (D2 : Boolean := True) <B>is</B> <B>new</B> T1 (D1 => D2);<BR>
<BR>
Y : T2;<BR>
<BR>
<B>package</B> I <B>is new</B> G (T2, Y);<BR>
<BR>
Y := (D1 => True); -- Oops! What happened to I.C1_Ren?</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Note
that if an implementation chooses to deallocate-then-reallocate on <FONT FACE="Arial, Helvetica">assignment_statement</FONT>s
assigning to unconstrained definite objects, then it cannot represent
renamings and access values as simple addresses, because the above rule
does not apply to all components of such an object. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>If it is
a generic formal object, then the assume-the-best or assume-the-worst
rules are applied as appropriate. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> An <FONT FACE="Arial, Helvetica">object_renaming_declaration</FONT>
declares a new view [of the renamed object] whose properties are identical
to those of the renamed view. [Thus, the properties of the renamed object
are not affected by the <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>.
In particular, its value and whether or not it is a constant are unaffected;
similarly, the constraints that apply to an object are not affected by
renaming (any constraint implied by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
of the <FONT FACE="Arial, Helvetica">object_renaming_declaration</FONT>
is ignored).] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Because the
constraints are ignored, it is a good idea to use the nominal subtype
of the renamed object when writing an <FONT FACE="Arial, Helvetica">object_renaming_declaration</FONT>.
</FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Example of renaming
an object:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Examples"><TT><B>declare</B><BR>
L : Person <B>renames</B> Leftmost_Person; --<I> see <A HREF="AA-3-10-1.html">3.10.1</A></I><BR>
<B>begin</B><BR>
L.Age := L.Age + 1;<BR>
<B>end</B>;</TT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The phrase ``subtype ... as defined
in a corresponding object declaration, component declaration, or component
subtype indication,'' from RM83-8.5(5), is incorrect in Ada 95; therefore
we removed it. It is incorrect in the case of an object with an indefinite
unconstrained nominal subtype. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-8-5.html">Previous</A> <A HREF="AA-8-5-2.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|