📄 1076_3.html
字号:
<html>
<head>
<title>VHDL LRM- Introduction</title>
</head>
<body>
<h1><a name="3">Section 3</a></h1>
<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>
<HR>
<h1>Types</h1>
<p>
<p>This section describes the various categories of types that are provided by the language as well as those specific types that are predefined. The declarations of all predefined types are contained in package STANDARD, the declaration of which appears in Section 14.
<p>A type is characterized by a set of values and a set of operations. The set of operations of a type includes the explicitly declared subprograms that have a parameter or result of the type. The remaining operations of a type are the basic operations and the predefined operators (see <a href = "1076_7.HTM#7.2"> 7.2 </a> ). These operations are each implicitly declared for a given type declaration immediately after the type declaration and before the next explicit declaration, if any.
<p>A <i>basic operation</i> is an operation that is inherent in one of the following:
<ul>
<p>-- An assignment (in assignment statements and initializations)
<p>-- An allocator
<p>-- A selected name, an indexed name, or a slice name
<p>-- A qualification (in a qualified expression), an explicit type conversion, a formal or actual part in the form of a type conversion, or an implicit type conversion of a value of type <i>universal_integer</i> or <i>universal_real</i> to the corresponding value of another numeric type
<p>-- A numeric literal (for a universal type), the literal <b>null</b> (for an access type), a string literal, a bit string literal, an aggregate, or a predefined attribute
</ul>
<p>There are four classes of types. <i>Scalar</i> types are integer types, floating point types, physical types, and types defined by an enumeration of their values; values of these types have no elements. <i>Composite</i> types are array and record types; values of these types consist of element values. <i>Access</i> types provide access to objects of a given type. <i>File</i> types provide access to objects that contain a sequence of values of a given type.
<p>The set of possible values for an object of a given type can be subjected to a condition that is called a <i>constraint</i> (the case where the constraint imposes no restriction is also included); a value is said to <i>satisfy</i> a constraint if it satisfies the corresponding condition. A <i>subtype</i> is a type together with a constraint. A value is said to <i>belong to a subtype</i> of a given type if it belongs to the type and satisfies the constraint; the given type is called the <i>base type</i> of the subtype. A type is a subtype of itself; such a subtype is said to be <i>unconstrained</i> (it corresponds to a condition that imposes no restriction). The base type of a type is the type itself.
<p>The set of operations defined for a subtype of a given type includes the operations defined for the type; however, the assignment operation to an object having a given subtype only assigns values that belong to the subtype. Additional operations, such as qualification (in a qualified expression) are implicitly defined by a subtype declaration.
<p>The term <i>subelement</i> is used in this manual in place of the term element to indicate either an element, or an element of another element or subelement. Where other subelements are excluded, the term <i>element</i> is used instead.
<p>A given type must not have a subelement whose type is the given type itself.
<p> A<i> member</i> of an object is either
<ul>
<p>- A slice of the object,
<p>- A sub element of the object, or
<p>- A slice of a sub eleent of the object
</ul>
<p>The name of a class of types is used in this manual as a qualifier for objects and values that have a type of the class considered. For example, the term <i>array object</i> is used for an object whose type is an array type; similarly, the term <i>access value</i> is used for a value of an access type.
<p>NOTE<i>--</i>The set of values of a subtype is a subset of the values of the base type. This subset need not be a proper subset.
<h2><a name="3.1"> <a href = "1076_3.HTM#3.1"> 3.1 </a> Scalar Types</a> </h2>
<p>Scalar types consist of <i>enumeration types, integer types, physical types</i>, and <i>floating point types</i>. Enumeration types and integer types are called <i>discrete</i> types. Integer types, floating point types,and physical types are called <i>numeric</i> types. All scalar types are ordered; that is, all relational operators are predefined for their values. Each value of a discrete or physical type has a position number that is an integer value.
<pre> scalar_type_definition ::=
enumeration_type_definition | integer_type_definition
| floating_type_definition |physical_type_definition
range_constraint ::= <b>range</b> range
range ::=
<i>range</i>_attribute_name
| simple_expression direction simple_expression
direction ::= <b>to</b> | <b>downto</b>
</pre>
<p>A range specifies a subset of values of a scalar type. A range is said to be a <i>null</i> range if the specified subset is empty.
<p>The range L <b>to</b> R is called an <i>ascending</i> range; if L > R, then the range is a null range. The range L <b>downto</b> R is called a <i>descending</i> range; if L < R, then the range is a null range. The smaller of L and R is called the <i>lower bound</i>, and the larger, the <i>upper bound</i>, of the range. The value V is said to <i>belong to the range</i> if the relations (<i>lower bound</i> <= V) and (V <= <i>upper bound</i>) are both true and the range is not a null range. The operators>, <, and <= in the preceding definitions are the predefined operators of the applicable scalar type.
<p>For values of discrete or physical types, a value V1 is said to be <i>to the left of</i> a value V2 within a given range if both V1 and V2 belong to the range and either the range is an ascending range and V2 is the successor of V1 or the range is a descending range and V2 is the predecessor of V1. A list of values of a given range is in <i>left</i> <i>to right order</i> if each value in the list is to the left of the next value in the list within that range, except for the last value in the list.
<p>If a range constraint is used in a subtype indication, the type of the expressions (likewise, of the bounds of a range attribute) must be the same as the base type of the type mark of the subtype indication. A range constraint is <i>compatible</i> with a subtype if each bound of the range belongs to the subtype or if the range constraint defines a null range. Otherwise, the range constraint is not compatible with the subtype.
<p>The direction of a range constraint is the same as the direction of its range.
<p>NOTE--Indexing and iteration rules use values of discrete types.
<h3><a name="3.1.1"> <a href = "1076_3.HTM#3.1.1"> 3.1.1 </a> Enumeration types</a></h3>
<p>An enumeration type definition defines an enumeration type.
<pre> enumeration_type_definition ::=
( enumeration_literal { , enumeration_literal } )
enumeration_literal ::= identifier | character_literal
</pre>
<p>The identifiers and character literals listed by an enumeration type definition must be distinct within the enumeration type definition. Each enumeration literal is the declaration of the corresponding enumeration literal; for the purpose of determining the parameter and result type profile of an enumeration literal, this declaration is equivalent to the declaration of a parameterless function whose designator is the same as the enumeration literal and whose result type is the same as the enumeration type.
<p>An enumeration type is said to be a <i>character type</i> if at least one of its enumeration literals is a character literal.
<p>Each enumeration literal yields a different enumeration value. The predefined order relations between enumeration values follow the order of corresponding position numbers. The position number of the value of the first listed enumeration literal is zero; the position number for each additional enumeration literal is one more than that of its predecessor in the list.
<p>If the same identifier or character literal is specified in more than one enumeration type definition, the corresponding literals are said to be <i>overloaded</i>. At any place where an overloaded enumeration literal occurs in the text of a program, the type of the enumeration literal is determined according to the rules for overloaded subprograms (see <a href = "1076_2.HTM#2.3"> 2.3 </a> ).
<p>Each enumeration type definition defines an ascending range.
<p><i>Examples:</i>
<pre> <b>type</b> MULTI_LEVEL_LOGIC <b>is</b> (LOW, HIGH, RISING, FALLING, AMBIGUOUS) ;
<b>type</b> BIT <b>is</b> ('0','1') ;
<b>type</b> SWITCH_LEVEL <b>is</b> ('0','1','X') ; -- Overloads '0' and '1'
</pre>
<h4><a name="3.1.1.1"> <a href = "1076_3.HTM#3.1.1.1"> 3.1.1.1 </a> Predefined enumeration types</a></h4>
<p>The predefined enumeration types are CHARACTER, BIT, BOOLEAN, SEVERITY_LEVEL, FILE_OPEN_KIND, and FILE_OPEN_STATUS.
<p>The predefined type CHARACTER is a character type whose values are the 256 characters of the ISO 8859-1 character set. Each of the 191 graphic characters of this character set is denoted by the corresponding character literal.
<p>The declarations of the predefined types CHARACTER, BIT, BOOLEAN, SEVERITY_LEVEL, FILE_OPEN_KIND, and FILE_OPEN_STATUS appear in package STANDARD in Section 14.
<h4>NOTES</h4>
<p>1--The first 17 nongraphic elements of the predefined type CHARACTER (from NUL through DEL) are the ASCII abbreviations for the nonprinting characters in the ASCII set (except for those noted in Section 14). The ASCII names are chosen as ISO 8859-1 does not assign them abbreviations. The next 16 (C128through C159) are also not assigned abbreviations, so names unique to VHDL are assigned.
<p>2--Type BOOLEAN can be used to model either active high or active low logic depending on the particular conversion functions chosen to and from type BIT.
<h3><a name="3.1.2"> <a href = "1076_3.HTM#3.1.2"> 3.1.2 </a> Integer types</a></h3>
<p>An integer type definition defines an integer type whose set of values includes those of the specified range.
<pre> integer_type_definition ::= range_constraint
</pre>
<p>An integer type definition defines both a type and a subtype of that type. The type is an anonymous type, the range of which is selected by the implementation; this range must be such that it wholly contains the range given in the integer type definition. The subtype is a named subtype of this anonymous base type, where the name of the subtype is that given by the corresponding type declaration and the range of the subtype is the given range.
<p>Each bound of a range constraint that is used in an integer type definition must be a locally static expression of some integer type, but the two bounds need not have the same integer type. (Negative bounds are allowed.)
<p>Integer literals are the literals of an anonymous predefined type that is called <i>universal_integer </i>in this standard. Other integer types have no literals. However, for each integer type there exists an implicit conversion that converts a value of type <i>universal_integer</i> into the corresponding value (if any) of the integer type (see <a href = "1076_7.HTM#7.3.5"> 7.3.5 </a> ).
<p>The position number of an integer value is the corresponding value of the type <i>universal_integer</i>.
<p>The same arithmetic operators are predefined for all integer types (see <a href = "1076_7.HTM#7.2"> 7.2 </a> ). It is an error if the execution of such an operation (in particular, an implicit conversion) cannot deliver the correct result (that is, if the value corresponding to the mathematical result is not a value of the integer type).
<p>An implementation may restrict the bounds of the range constraint of integer types other than type <i>universal_integer</i>. However, an implementation must allow the declaration of any integer type whose range is wholly contained within the bounds -2147483647 and +2147483647 inclusive.
<p><i>Examples:</i>
<pre> <b>type</b> TWOS_COMPLEMENT_INTEGER <b>is</b> <b>range</b> -32768 <b>to</b> 32767;
<b>type</b> BYTE_LENGTH_INTEGER <b>is</b> <b>range</b> 0 <b>to</b> 255;
<b>type</b> WORD_INDEX <b>is</b> <b>range</b> 31 <b>down to</b> 0;
<b>subtype</b> HIGH_BIT_LOW <b>is</b> BYTE_LENGTH_INTEGER <b>range</b> 0 <b>to</b> 127;
</pre>
<h4><a name="3.1.2.1"> <a href = "1076_3.HTM#3.1.2.1"> 3.1.2.1 </a> Predefined integer types</a></h4>
<p>The only predefined integer type is the type INTEGER. The range of INTEGER is implementation dependent, but it is guaranteed to include the range -2147483647to +2147483647. It is defined with an ascending range.
<p>NOTE--The range of INTEGER in a particular implementation may be determined from the 'LOW and 'HIGH attributes.
<h3><a name="3.1.3"> <a href = "1076_3.HTM#3.1.3"> 3.1.3 </a> Physical types</a></h3>
<p>Values of a physical type represent measurements of some quantity. Any value of a physical type is an integral multiple of the primary unit of measurement for that type.
<pre> physical_type_definition ::=
range_constraint
<b>units</b>
primary_unit_declaration
{ secondary_unit_declaration }
<b>end</b> <b>units</b> [ <i>physical_type</i>_simple_name ]
primary_unit_declaration ::= identifier
secondary_unit_declaration ::= identifier = physical_literal ;
physical_literal ::= [ abstract_literal ] <i>unit</i>_name
</pre>
<p>A physical type definition defines both a type and a subtype of that type. The type is an anonymous type, the range of which is selected by the implementation; this range must be such that it wholly contains the range given in the physical type definition. The subtype is a named subtype of this anonymous base type, where the name of the subtype is that given by the corresponding type declaration and the range of the subtype is the given range.
<p>Each bound of a range constraint that is used in a physical type definition must be a locally static expression of some integer type, but the two bounds need not have the same integer type. (Negative bounds are allowed.)
<p>Each unit declaration (either the primary unit declaration or a secondary unit declaration) defines a <i>unit name</i>. Unit names declared in secondary unit declarations must be directly or indirectly defined in terms of integral multiples of the primary unit of the type declaration in which they appear. The position numbers of unit names need not lie within the range specified by the range constraint.
<p>If a simple name appears at the end of a physical type declaration, it must repeat the identifier of the type declaration in which the physical type definition is included.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -