?? 1076_2.html
字號:
| file_declaration
| alias_declaration
| component_declaration
| attribute_declaration
| attribute_specification
| disconnection_specification
| use_clause
| group_template_declaration
| group_declaration
</pre>
<p>If a simple name appears at the end of the package declaration, it must repeat the identifier of the package declaration.
<p>Items declared immediately within a package declaration become visible by selection within a given design unit wherever the name of that package is visible in the given unit. Such items may also be made directly visible by an appropriate use clause (see <a href = "1076_10.HTM#10.4"> 10.4 </a> ).
<p>NOTE--Not all packages will have a package body. In particular, a package body is unnecessary if no subprograms or deferred constants are declared in the package declaration.
<p><i>Examples:</i>
<pre>-- A package declaration that needs no package body:
<b> package</b> TimeConstants <b>is</b>
<b>constant</b> tPLH : Time := 10 ns;
<b>constant</b> tPHL : Time := 12 ns;
<b>constant</b> tPLZ : Time := 7 ns;
<b>constant</b> tPZL : Time := 8 ns;
<b>constant</b> tPHZ : Time := 8 ns;
<b>constant</b> tPZH : Time := 9 ns;
<b>end</b> TimeConstants ;
-- A package declaration that needs a package body:
<b>package</b> TriState <b>is</b>
<b>type </b>Tri <b>is</b> ('0', '1', 'Z', 'E');
<b>function</b> BitVal (Value: Tri) <b>return</b> Bit ;
<b>function</b> TriVal (Value: Bit) <b>return</b> Tri;
<b>type</b> TriVector <b>is array</b> (Natural <b>range</b> <>) <b>of</b> Tri ;
<b>function</b> Resolve (Sources: TriVector) <b>return</b> Tri ;
<b>end package</b> TriState ;
</pre>
<h2><a name="2.6"> <a href = "1076_2.HTM#2.6"> 2.6 </a> Package bodies</a></h2>
<p>A package body defines the bodies of subprograms and the values of deferred constants declared in the interface to the package.
<pre> package_body ::=
<b>package body</b> <i>package</i>_simple_name <b>is</b>
package_body_declarative_part
<b>end</b> [ <b>package</b> <b>body</b> ] [ <i>package</i>_simple_name ] ;
package_body_declarative_part ::=
{ package_body_declarative_item }
package_body_declarative_item ::=
subprogram_declaration
| subprogram_body
| type_declaration
| subtype_declaration
| constant_declaration
| <i>shared</i>_variable_declaration
| file_declaration
| alias_declaration
| use_clause
| group_template_declaration
| group_declaration
</pre>
<p>The simple name at the start of a package body must repeat the package identifier. If a simple name appears at the end of the package body, it must be the same as the identifier in the package declaration.
<p>In addition to subprogram body and constant declarative items, a package body may contain certain other declarative items to facilitate the definition of the bodies of subprograms declared in the interface. Items declared in the body of a package cannot be made visible outside of the package body.
<p>If a given package declaration contains a deferred constant declaration (see <a href = "1076_4.HTM#4.3.1.1"> 4.3.1.1 </a> ), then a constant declaration with the same identifier must appear as a declarative item in the corresponding package body. This object declaration is called the <i>full</i> declaration of the deferred constant. The subtype indication given in the full declaration must conform to that given in the deferred constant declaration.
<p>Within a package declaration that contains the declaration of a deferred constant, and within the body of that package (before the end of the corresponding full declaration), the use of a name that denotes the deferred constant is only allowed in the default expression for a local generic, local port, or formal parameter. The result of evaluating an expression that references a deferred constant before the elaboration of the corresponding full declaration is not defined by the language.
<p><i>Example:</i>
<pre> <b>package</b> <b>body</b> TriState <b>is</b>
<b>function</b> BitVal (Value: Tri) <b>return</b> Bit <b>is</b>
<b>constant</b> Bits : Bit_Vector := "0100";
<b>begin</b>
<b>return </b>Bits(Tri'Pos(Value));
<b>end</b>;
<b>function</b> TriVal (Value: Bit) <b>return</b> Tri <b>is</b>
<b> begin</b>
<b>return </b>Tri'Val(Bit'Pos(Value));
<b>end</b>;
<b>function</b> Resolve (Sources: TriVector) <b>return</b> Tri <b>is</b>
<b>variable</b> V: Tri := 'Z';
<b>begin</b>
<b>for</b> i <b>in</b> Sources'Range <b>loop</b>
<b>if</b> Sources(i) /= 'Z' <b>then</b>
<b>if</b> V = 'Z' <b>then</b>
V := Sources(i);
<b>else</b>
<b>return </b>'E';
<b>end if</b>;
<b>end if</b>;
<b>end loop</b>;
<b>return</b> V;
<b>end</b>;
<b> end package body</b> TriState ;
</pre>
<h2><a name="2.7"> <a href = "1076_2.HTM#2.7"> 2.7 </a> Conformance rules</a></h2>
<p>Whenever the language rules either require or allow the specification of a given subprogram to be provided in more than one place, the following variations are allowed at each place:
<ul>
<p>-- A numeric literal can be replaced by a different numeric literal if and only if both have the same value.
<p>-- A simple name can be replaced by an expanded name in which this simple name is the selector if and only if at both places the meaning of the simple name is given by the same declaration.
</ul>
<p>Two subprogram specifications are said to <i>conform</i> if, apart from comments and the above allowed variations, both specifications are formed by the same sequence of lexical elements and if corresponding lexical elements are given the same meaning by the visibility rules.
<p>Conformance is likewise defined for subtype indications in deferred constant declarations.
<p>1--A simple name can be replaced by an expanded name even if the simple name is itself the prefix of a selected name. For example, Q.R can be replaced by P.Q.R if Q is declared immediately within P.
<p>2--The subprogram specification of an impure function is never conformant to a subprogram specification of a pure function.
<p>3--The following specifications do not conform since they are not formed by the same sequence of lexical elements:
<pre> <b>procedure</b> P (X,Y : INTEGER)
<b>procedure</b> P (X: INTEGER; Y : INTEGER)
<b>procedure</b> P (X,Y : <b>in</b> INTEGER)
</pre>
<HR>
<a href="../../HTML/HOMEPG.HTM"><img src="HP.GIF" border=0></a>
<a href="1076_TOC.HTM"><img src="TOP.GIF" BORDER=0></a>
<a href="1076_1.HTM"><img src="LEFT.GIF" BORDER=0></a>
<a href="1076_3.HTM"><img src="RIGHT.GIF" BORDER=0></a>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -