Re: [sv-bc] enum.num method

From: Arturo Salz <Arturo.Salz_at_.....>
Date: Tue Aug 23 2005 - 10:53:13 PDT
Paul,

Your suggestion of having the ability to call static methods on a type
makes a lot of sense. By static, I mean methods whose return value is 
only a function of the static (type) information. If we were to define the
built-in static methods then extending the :: operator to allow calling 
static methods on enumerated types seems straightforward. Currently, 
the static enum methods are num(), first(), and last().
That would allow code like: 
    for( int j = 0; j < color::num; j++ ) ...
    while( c != color::last ) ...

The vhdl-like extensions you suggest may also be useful extensions.

    Arturo

----- Original Message ----- 
From: "Paul Graham" <pgraham@cadence.com>
To: <sv-bc@eda.org>
Sent: Tuesday, August 23, 2005 9:25 AM
Subject: [sv-bc] enum.num method


The num() method for enumeration types is a bit confusing to
use:

    typedef enum {red, blue, green} color;

    y = red.num;

Here, the expression red.num has nothing to do with the enum
literal red.  Instead it returns a property of type color.
In contrast, the other enum methods all return properties
of their enum value arguments.  I think you'd want to write:

    y = color.num;

but I don't think that a type name is allowed as a
method_call_root.

I wonder if something like the vhdl 'pos and 'val attributes
would be useful:

    function int pos() 

    returns the position (indexed from 0) of the enum
    literal in the type.

    function enum val(unsigned int N)

    returns the value of the N'th position of the enum type

So:

    red.pos() == 0
    red.val(2) == green // looks funny to me
    color.val(2) == green // better...


Paul
Received on Tue Aug 23 10:50:54 2005

This archive was generated by hypermail 2.1.8 : Tue Aug 23 2005 - 10:51:32 PDT