?? 1076_3.html
字號:
<h4>NOTES</h4>
<p>1--An access value delivered by an allocator can be assigned to several variables of the corresponding access type. Hence, it is possible for an object created by an allocator to be designated by more than one variable of the access type. An access value can only designate an object created by an allocator; in particular, it cannot designate an object declared by an object declaration.
<p>2--If the type of the object designated by the access value is an array type, this object is constrained with the array bounds supplied implicitly or explicitly for the corresponding allocator.
<h3><a name="3.3.1"> <a href = "1076_3.HTM#3.3.1"> 3.3.1 </a> Incomplete type declarations</a></h3>
<p>The designated type of an access type can be of any type except a file type (see <a href = "1076_3.HTM#3.3"> 3.3 </a> ). In particular, the type of an element of the designated type can be another access type or even the same access type. This permits mutually dependent and recursive access types. Declarations of such types require a prior incomplete type declaration for one or more types.
<pre> incomplete_type_declaration ::= <b>type</b> identifier ;
</pre>
<p>For each incomplete type declaration there must be a corresponding full type declaration with the same identifier. This full type declaration must occur later and immediately within the same declarative part as the incomplete type declaration to which it corresponds.
<p>Prior to the end of the corresponding full type declaration, the only allowed use of a name that denotes a type declared by an incomplete type declaration is as the type mark in the subtype indication of an access type definition; no constraints are allowed in this subtype indication.
<p><i>Example of a recursive type:</i>
<pre> <b>type</b> CELL; -- An incomplete type declaration.
<b>type</b> LINK <b>is</b> <b>access</b> CELL;
<b>type</b> CELL <b>is</b>
<b>record</b>
VALUE : INTEGER;
SUCC : LINK;
PRED : LINK;
<b>end</b> <b>record</b> CELL;
<b>variable</b> HEAD : LINK := <b>new</b> CELL'(0, <b>null</b>, <b>null</b>);
<b>variable</b> \NEXT\ : LINK := HEAD.SUCC;
</pre>
<p><i>Examples of mutually dependent access types:</i>
<pre> <b>type</b> PART; -- Incomplete type declarations.
<b>type</b> WIRE;
<b>type</b> PART_PTR <b>is access</b> PART;
<b>type</b> WIRE_PTR <b>is access</b> WIRE;
<b>type</b> PART_LIST <b>is array</b> (POSITIVE <b>range</b> <>) <b>of</b> PART_PTR;
<b>type</b> WIRE_LIST <b>is array</b> (POSITIVE <b>range</b> <>) <b>of</b> WIRE_PTR;
<b>type</b> PART_LIST_PTR <b>is access</b> PART_LIST;
<b>type</b> WIRE_LIST_PTR <b>is access</b> WIRE_LIST;
<b>type</b> PART <b>is</b>
<b>record</b>
PART_NAME : STRING (1 <b>to</b> MAX_STRING_LEN);
CONNECTIONS : WIRE_LIST_PTR;
<b>end record</b>;
<b>type</b> WIRE <b>is</b>
<b>record</b>
WIRE_NAME : STRING (1 <b>to</b> MAX_STRING_LEN);
CONNECTS : PART_LIST_PTR;
<b>end record</b>;
</pre>
<h3><a name="3.3.2"> <a href = "1076_3.HTM#3.3.2"> 3.3.2 </a> Allocation and deallocation of objects</a></h3>
<p>An object designated by an access value is allocated by an allocator for that type. An allocator is a primary of an expression; allocators are described in <a href = "1076_7.HTM#7.3.6"> 7.3.6 </a> . For each access type, a deallocation operation is implicitly declared immediately following the full type declaration for the type. This deallocation operation makes it possible to deallocate explicitly the storage occupied by a designated object.
<p>Given the following access type declaration:
<pre> <b>type</b> AT <b>is access</b> T;
</pre>
<p>the following operation is implicitly declared immediately following the access type declaration:
<pre> <b>procedure</b> DEALLOCATE (P: <b>inout</b> AT) ;
</pre>
<p>Procedure DEALLOCATE takes as its single parameter a variable of the specified access type. If the value of that variable is the null value for the specified access type, then the operation has no effect. If the value of that variable is an access value that designates an object, the storage occupied by that object is returned to the system and may then be reused for subsequent object creation through the invocation of an allocator. The access parameter P is set to the null value for the specified type.
<p>NOTE--If a pointer is copied to a second variable and is then deallocated,the second variable is <i>not</i> set to null and thus references invalid storage.
<h2><a name="3.4"> <a href = "1076_3.HTM#3.4"> 3.4 </a> File types</a></h2>
<p>A file type definition defines a file type. File types are used to define objects representing files in the host system environment. The value of a file object is the sequence of values contained in the host system file.
<pre> file_type_definition ::= <b>file</b> <b>of</b> type_mark
</pre>
<p>The type mark in a file type definition defines the subtype of the values contained in the file. The type mark may denote either a constrained or an unconstrained subtype. The base type of this subtype must not be a file type or an access type. If the base type is a composite type, it must not contain a subelement of an access type. If the base type is an array type, it must be a one-dimensional array type.
<p><i>Examples:</i>
<pre> <b>file of</b> STRING -- Defines a file type that can contain
-- an indefinite number of strings of arbitrary length.
<b>file</b> <b>of</b> NATURAL -- Defines a file type that can contain
-- only nonnegative integer values.
</pre>
<h3><a name="3.4.1"> <a href = "1076_3.HTM#3.4.1"> 3.4.1 </a> File operations</a></h3>
<p>The language implicitly defines the operations for objects of a file type. Given the following file type declaration:
<pre> <b>type</b> FT <b>is file of</b> TM;
</pre>
<p>where type mark TM denotes a scalar type, a record type, or a constrained array subtype, the following operations are implicitly declared immediately following the file type declaration:
<pre> <b>procedure</b> FILE_OPEN (<b>file</b> F: FT;
External_Name: <b>in</b> STRING;
Open_Kind: <b>in</b> FILE_OPEN_KIND := READ_MODE);
<b>procedure</b> FILE_OPEN (Status: <b>out</b> FILE_OPEN_STATUS;
<b> file</b> F: FT;
External_Name: <b>in</b> STRING;
Open_Kind: <b>in</b> FILE_OPEN_KIND := READ_MODE);
<b>procedure</b> FILE_CLOSE (<b>file</b> F: FT);
<b>procedure</b> READ (<b>file</b> F: FT; VALUE: <b>out</b> TM);
<b>procedure</b> WRITE (<b>file</b> F: FT; VALUE: <b>in</b> TM);
<b>function</b> ENDFILE (<b>file</b> F:<b> </b>FT) <b>return</b> BOOLEAN;
</pre>
<p>The FILE_OPEN procedures open an external file specified by the External_Name parameter and associate it with the file object F. If the call to FILE_OPEN is successful (see below), the file object is said to be <i>open</i> and the file object has an <i>access mode</i> dependent on the value supplied to the Open_Kind parameter (see <a href = "1076_14.HTM#14.2"> 14.2 </a> ).
<ul>
<p>-- If the value supplied to the Open_Kind parameter is READ_MODE, the access mode of the file object is <i>read-only</i>. In addition, the file object is initialized so that a subsequent READ will return the first value in the external file. Values are read from the file object in the order that they appear in the external file.
<p>-- If the value supplied to the Open_Kind parameter is WRITE_MODE, the access mode of the file object is <i>write-only</i>. In addition, the external file is made initially empty. Values written to the file object are placed in the external file in the order in which they are written.
<p>-- If the value supplied to the Open_Kind parameter is APPEND_MODE, the access mode of the file object is <i>write-only</i>. In addition, the file object is initialized so that values written to it will be added to the end of the external file in the order in which they are written.
</ul>
<p>In the second form of FILE_OPEN, the value returned through the Status parameter indicates the results of the procedure call:
<ul>
<p>-- A value of OPEN_OK indicates that the call to FILE_OPEN was successful. If the call to FILE_OPEN specifies an external file that does not exist at the beginning of the call, and if the access mode of the file object passed to the call is write-only, then the external file is created.
<p>-- A value of STATUS_ERROR indicates that the file object already has an external file associated with it.
<p>-- A value of NAME_ERROR indicates that the external file does not exist (in the case of an attempt to read from the external file) or the external file cannot be created (in the case of an attempt to write or append to an external file that does not exist). This value is also returned if the external file cannot be associated with the file object for any reason.
<p>-- A value of MODE_ERROR indicates that the external file cannot be opened with the requested Open_Kind.
</ul>
<p>The first form of FILE_OPEN causes an error to occur if the second form of FILE_OPEN, when called under identical conditions, would return a Status value other than OPEN_OK.
<p>A call to FILE_OPEN of the first form is <i>successful</i> if and only if the call does not cause an error to occur. Similarly, a call to FILE_OPEN of the second form is successful if and only if it returns a Status value of OPEN_OK.
<p>If a file object F is associated with an external file, procedure FILE_CLOSE terminates access to the external file associated with F and closes the external file. If F is not associated with an external file, then FILE_CLOSE has no effect. In either case, the file object is no longer open after a call to FILE_CLOSE that associates the file object with the formal parameter F.
<p>An implicit call to FILE_CLOSE exists in a subprogram body for every file object declared in the corresponding subprogram declarative part. Each such call associates a unique file object with the formal parameter F and is called whenever the corresponding subprogram completes its execution.
<p>Procedure READ retrieves the next value from a file; it is an error if the access mode of the file object is write-only or if the file object is not open. Procedure WRITE appends a value to a file; it is similarly an error if the access mode of the file object is read-only or if the file is not open. Function ENDFILE returns FALSE if a subsequent READ operation on an open file object whose access mode is read-only can retrieve another value from the file;otherwise, it returns TRUE. Function ENDFILE always returns TRUE for an open file object whose access mode is write-only. It is an error if ENDFILE is called on a file object that is not open.
<p>For a file type declaration in which the type mark denotes an unconstrained array type, the same operations are implicitly declared, except that the READ operation is declared as follows:
<pre> <b>procedure</b> READ (<b>file</b> F: FT; VALUE: <b>out</b> TM; LENGTH: <b>out</b> Natural);
</pre>
<p>The READ operation for such a type performs the same function as the READ operation for other types, but in addition it returns a value in parameter LENGTH that specifies the actual length of the array value read by the operation. If the object associated with formal parameter VALUE is shorter than this length, then only that portion of the array value read by the operation that can be contained in the object is returned by the READ operation, and the rest of the value is lost. If the object associated with formal parameter VALUE is longer than this length, then the entire value is returned and remaining elements of the object are unaffected by the READ operation.
<p>An error will occur when a READ operation is performed on file F if ENDFILE(F) would return TRUE at that point.
<p>NOTE--Predefined package TEXTIO is provided to support formatted human-readable I/O. It defines type TEXT (a file type representing files of variable-length text strings) and type LINE (an access type that designates such strings). READ and WRITE operations are provided in package TEXTIO that append or extract data from a single line. Additional operations are provided to read or write entire lines and to determine the status of the current line or of the file itself. Package TEXTIO is defined in <a href = "1076_14.HTM">Section 14</a>.
<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_2.HTM"><img src="LEFT.GIF" BORDER=0></a>
<a href="1076_4.HTM"><img src="RIGHT.GIF" BORDER=0></a>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -