What is the base type?

  • Thread starter Valentin Tihhomirov
  • Start date
V

Valentin Tihhomirov

Guest
Is it the immediate predecessor of the subtype or it is the root,
declared by type_definition or predefined superroot (e.g.
$universal_integer)?

From the

qualified_expression ::= type_mark ' ( expression )

and statement *"The operand shall have the same type as the base typeof
the type mark"* it follows that the base type is the root because
literals are of the root type rather than immediate predcessor.

On the other hand, the "Subtypes" section in Ashenden creates an
impression that the base base type is not the root but immediate
predecessor: "We can represent such objects by declaring a subtype,
which defines a restricted set of values from a base type.. The sub-type
declaration defines the identifier as a subtype of the base type
specified by the type mark" And, I see in the "Type Declarations"
section, which remarks that two declared types with are different
despite the same definition, does not mention that declarations define
the base types.


LRM Section on types does not clarify the things:

"A subtypeis a type together with a constraint. A value is said to
belong to a subtypeof a given type if it belongs to the type and
satisfies the constraint; the given type is called the base typeof the
subtype. A type is a subtype of itself; such a subtype is said to be
unconstrained (it corresponds to a condition that imposes no
restriction). The base type of a type is the type itself."


Apart from that, what is the point of defining both type and subtype,
("array_definition defines both an array type and a subtype of this type")?
 
On 20/01/13 23:54, Valentin Tihhomirov wrote:
Is it the immediate predecessor of the subtype or it is the root,
declared by type_definition or predefined superroot (e.g.
$universal_integer)?

From the

qualified_expression ::= type_mark ' ( expression )

and statement *"The operand shall have the same type as the base typeof
the type mark"* it follows that the base type is the root because
literals are of the root type rather than immediate predcessor.

On the other hand, the "Subtypes" section in Ashenden creates an
impression that the base base type is not the root but immediate
predecessor: "We can represent such objects by declaring a subtype,
which defines a restricted set of values from a base type.. The sub-type
declaration defines the identifier as a subtype of the base type
specified by the type mark" And, I see in the "Type Declarations"
section, which remarks that two declared types with are different
despite the same definition, does not mention that declarations define
the base types.


LRM Section on types does not clarify the things:

"A subtypeis a type together with a constraint. A value is said to
belong to a subtypeof a given type if it belongs to the type and
satisfies the constraint; the given type is called the base typeof the
subtype. A type is a subtype of itself; such a subtype is said to be
unconstrained (it corresponds to a condition that imposes no
restriction). The base type of a type is the type itself."


Apart from that, what is the point of defining both type and subtype,
("array_definition defines both an array type and a subtype of this type")?
I think the LRM is clear - the key sentence you've quoted is from this
section (1076-2002

" A subtype is a type together with a constraint. A value is
said to belong to a subtype of a given type if it belongs to the type
and satisfies the constraint; the given type is called the base type of
the subtype."

i.e. "the given type is called the base type of the subtype".

Regarding the quote from the definition of qualified expression, the
operand of a qualified expression doesn't have to be a literal. A common
use case is to qualify the type of a concatenation in a case expression,
e.g.

process (A,B) -- A and B are std_logic
subtype v2t IS std_logic_vector(1 downto 0);
begin
case v2t'(A&B) is

because the expression A&B is not of a statically determinable type.

regards
Alan



--
Alan Fitch
 
LRM Section on types does not clarify the things:
"A subtypeis a type together with a constraint. A value is said to
belong to a subtypeof a given type if it belongs to the type and
satisfies the constraint; the given type is called the base typeof the
subtype. A type is a subtype of itself; such a subtype is said to be
unconstrained (it corresponds to a condition that imposes no
restriction). The base type of a type is the type itself."

Could you please clarify? Does it say that subtypes are always based on
the root type rather than form a hierarchy of subtypes?
 
On 22/01/13 10:42, valtih1978 wrote:
LRM Section on types does not clarify the things:
"A subtypeis a type together with a constraint. A value is said to
belong to a subtypeof a given type if it belongs to the type and
satisfies the constraint; the given type is called the base typeof the
subtype. A type is a subtype of itself; such a subtype is said to be
unconstrained (it corresponds to a condition that imposes no
restriction). The base type of a type is the type itself."

Could you please clarify? Does it say that subtypes are always based on
the root type rather than form a hierarchy of subtypes?
My interpretation is that subtypes are not based on a root type, they
are based on a type.

In the 1076-2002 standard it says regarding universal integer

"Integer literals are the literals of an anonymous predefined type that
is called universal_integer 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 universal_integer into the
corresponding value (if any) of the integer type (see 7.3.5). The
position number of an integer value is the corresponding value of the
type universal_integer."

I interpret that to mean that universal integer is an anonymous
predefined type which is infinite in range.

std.standard.integer is a type whose literals are the literals of
universal integer, but which has implementation defined range.

A user defined integer type is a type whose literals map on to literals
of universal integer, which has user defined range.

A subtype is then a constrained version of a type.

So for instance

-- a type whose literals map to those of universal integer, but which
has limits
type myint is integer range 0 to 10;

-- a subtype of
subtype smallint is myint range 1 to 2;

A type and its subtype can be assigned to each other. Different types
cannot be assigned without type conversion.

e.g.

variable A : integer;
variable B : myint;
variable C : smallint;

begin
A := B; -- illegal, different types
A := integer(B); -- legal, closely related types
B := C; -- legal, type and subtype

I'm not a computer scientist though, so I may have mis-understood your
question; but I think there is not a hierarchy of subtypes, a subtype is
based on the type of which it is a subtype, and that's it.

regards
Alan

--
Alan Fitch
 
subtype ST is INTEGER range 1 to 10;
subtype SST is INTEGER range 2 to 8;

report SST'base'low

will print "-2147483648". That is, it seems that there is no hierarchy
of subtypes in VHDL. A subtype-based subtype is grandtype based behind
the scenes.
 
Summarizing Alan Fitch notes:

subtype TSHORT is INTEGER range 1 to 2;
subtype TSMALL is INTEGER range 4 to 6;
variable short: TSHORT;
variable small: TSMALL;

small := short; // failed during execution

This is acceptable and elaboration will not complain because subtypes
are compatible. They belong to the same type, the base. The type system
is flat again (if we do not consider the universal and other
supertypes). No matter if subtypes were declared over another subtype.
The base type is extracted from the subtype used as base and will be
used for defining a new subtype. For example, INTEGER will be the base
type for VERY_SMALL declared as

subtype VERY_SMALL is TSMALL range (4 to 6)
 
On 26/01/13 19:51, valtih1978 wrote:
Summarizing Alan Fitch notes:

subtype TSHORT is INTEGER range 1 to 2;
subtype TSMALL is INTEGER range 4 to 6;
variable short: TSHORT;
variable small: TSMALL;

small := short; // failed during execution

This is acceptable and elaboration will not complain because subtypes
are compatible. They belong to the same type, the base. The type system
is flat again (if we do not consider the universal and other
supertypes). No matter if subtypes were declared over another subtype.
The base type is extracted from the subtype used as base and will be
used for defining a new subtype. For example, INTEGER will be the base
type for VERY_SMALL declared as

subtype VERY_SMALL is TSMALL range (4 to 6)
Hi,
I agree - and I also found this (in section 4.2 of the IEEE 1076-2002
LRM, I don't have the 2008 LRM to hand)

"A subtype declaration declares a subtype.
subtype_declaration ::=
subtype identifier is subtype_indication ;
subtype_indication ::=
[ resolution_function_name ] type_mark [ constraint ]
type_mark ::=
type_name
| subtype_name
constraint ::=
range_constraint
| index_constraint
A type mark denotes a type or a subtype. If a type mark is the name of a
type, the type mark denotes this type
and also the corresponding unconstrained subtype. The base type of a
type mark is, by definition, the base
type of the type or subtype denoted by the type mark.
A subtype indication defines a subtype of the base type of the type mark.
"

Notice the last sentence,

regards
Alan

--
Alan Fitch
 

Welcome to EDABoard.com

Sponsor

Back
Top