Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Concatenate enumeration

40 views
Skip to first unread message

Pablo

unread,
Nov 23, 2009, 1:15:52 PM11/23/09
to
Hi, I have a enumerate type and I have another one which I want to add
some enumerations.
So:
type Enumerate_Type is
(
NONE,
READY
);
for Enumerate_Type use
(
NONE => 0,
READY=> 1
);
for Enumerate_Type'Size use 1;

and I want to create a new type Enumerate2_Type which could be the
form
type Enumerate_Type is
(
NONE,
READY,
OFF
);
for Enumerate_Type use
(
NONE => 0,
READY=> 1,
OFF => 2
);
for Enumerate_Type'Size use 2;

How to I do this without having to explicit clone the first one?
Thanks

Jeffrey R. Carter

unread,
Nov 23, 2009, 2:14:27 PM11/23/09
to

You can't. Enumeration types are not extensible.

You can do something similar in the reverse direction:

type Big is (None, Ready, Off);

subtype Small is Big range None .. Ready;

or

type Small is new Big range None .. Ready;

--
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail
09

Robert A Duff

unread,
Nov 23, 2009, 6:21:06 PM11/23/09
to

Note that all of the rep clauses above are unnecessary: the language
defines the default rep of enums to be (0, 1, ...),
and defines the 'Size to be 1 and 2 for the above.

If you want to confirm the 'Size, I'd do:

pragma Assert (Enumerate_Type'Size = 1);

for example.

>> How to I do this without having to explicit clone the first one?
>
> You can't. Enumeration types are not extensible.

Extensible enumeration types were proposed for Ada 9X,
but were dropped.

> You can do something similar in the reverse direction:
>
> type Big is (None, Ready, Off);
>
> subtype Small is Big range None .. Ready;
>
> or
>
> type Small is new Big range None .. Ready;

Right. And Big'Size = 2, and Small'Size = 1, by default.

- Bob

Eryndlia Mavourneen

unread,
Nov 24, 2009, 2:42:59 PM11/24/09
to

It sounds as if you want the binary values of your enumerations to be
concatenated within a field. You *can* do this by declaring a record
that has 2 fields, one for each enumeration. You then can use a
representation clause to specify that the first type is contained in,
say, the first bit of the record and that the second type is contained
in the next 2 bits of the record.

This has the effect of concatenating the bit representations of the
types, but, of course, it does not concatenate the enumerations at the
Ada level, that is, the literals themselves.

Eryndlia

Randy Brukardt

unread,
Nov 25, 2009, 5:53:07 PM11/25/09
to
"Robert A Duff" <bob...@shell01.TheWorld.com> wrote in message
news:wcctywk...@shell01.TheWorld.com...
...

>> You can't. Enumeration types are not extensible.
>
> Extensible enumeration types were proposed for Ada 9X,
> but were dropped.

And were proposed again for Ada 2005, and were dropped again. See
AI95-0261-1. I doubt it will ever be proposed again.

Randy.


Dmitry A. Kazakov

unread,
Nov 26, 2009, 3:59:48 AM11/26/09
to

These are different things. I think the OP didn't want an extensible type.
He wanted a new independent type constructed in some specific way.

To extend an enumeration type E that has to have the class (E'Class). This
is a lot of work.

To reuse names of the literals of E in some other type, you only need
reflection. E.g. an attribute, say, E'Domain, which would return
"universal-set" of its literals, then you could write:

type E is (None, Ready);
type E1 is E'Domain or (Off); -- = (None, Ready, Off)

Not very useful, but in other cases reflection could be very interesting.
For example, in generics:

generic
type T is array; -- Only this
package ... is
-- The [first] array index type would be T'Index (1)
-- The array element type would be T'Element etc

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Georg Bauhaus

unread,
Nov 26, 2009, 4:48:24 AM11/26/09
to
Dmitry A. Kazakov schrieb:

> Not very useful, but in other cases reflection could be very interesting.
> For example, in generics:
>
> generic
> type T is array; -- Only this
> package ... is
> -- The [first] array index type would be T'Index (1)
> -- The array element type would be T'Element etc
>

I'm probably dense. Is there a difference to what we have
now other than the unknown number of indexes of the array
type above?

generic
type T_Index is (<>);
type T_Element is private;
type T is array (T_Index range <>) of T_Element;
package ... is

Dmitry A. Kazakov

unread,
Nov 26, 2009, 5:03:59 AM11/26/09
to

The difference is in the number of formal parameters.

0 new messages