Problems with Access types

Discussion in 'VHDL' started by Tricky, Jul 18, 2008.

  1. Tricky

    Tricky Guest

    The following code is giving me the error: "Method cannot have a
    parameter of an access type."

    type A_t;
    type a_ptr is access A_t;

    type A_t is array(integer range <>) of integer;

    type T is protected

    procedure add( variable x : in A_ptr);
    procedure remove;
    impure function get( x, y : integer ) return integer;
    end protected T;


    type T is protected body

    type A_array_t is array(0 to 9) of a_ptr;
    variable A : a_array_t;
    variable idx : integer := 0;

    procedure add( variable x : in A_ptr) is
    begin
    if idx >= 10 then
    report "No more room left. Will not add new array." severity
    WARNING;
    else
    A(idx) := x;
    idx := idx + 1;
    end if;
    end procedure add;

    procedure remove is
    begin
    if idx = 0 then
    report "No more data to remove." severity WARNING;
    else
    DEALLOCATE( A(idx) );
    idx := idx - 1;
    end if;
    end procedure remove;

    impure function get(x, y : integer) return integer is
    begin
    return a(x)(y);
    end function get;
    end protected body T;


    This is a small test bit of VHDL to test out functionality of access
    and protected types, not real code.
    Essentiall, I want T to store multiple arrays of the same type with
    different sizes. Is it possible to do what I am doing, or am I outside
    the scope of VHDL?
     
    Tricky, Jul 18, 2008
    #1
    1. Advertising

  2. Tricky

    KJ Guest

    On Jul 18, 5:41 am, Tricky <> wrote:
    > The following code is giving me the error: "Method cannot have a
    > parameter of an access type."
    >
    > type A_t;
    >   type a_ptr is access A_t;
    >
    >   type A_t is array(integer range <>) of integer;
    >
    >   type T is protected
    >
    >     procedure add(  variable  x : in A_ptr);
    >     procedure remove;
    >     impure function  get( x, y : integer ) return integer;
    >   end protected T;


    <snip>
    >
    > This is a small test bit of VHDL to test out functionality of access
    > and protected types, not real code.
    > Essentiall, I want T to store multiple arrays of the same type with
    > different sizes. Is it possible to do what I am doing, or am I outside
    > the scope of VHDL?


    Nope, protected types can not have methods that take in pointers. You
    *can* use access type in the body of the code that implements the
    method, but not on the interface to the method. An example would be,
    you can have a protected type that receives a file name (i.e. a
    string) that opens the file, reads the data, etc. and therefore will
    use access types internally but you can't read a file and then pass a
    pointer to the file data in to a method.

    Also remember that 'T' is a type, you'll have separate variables each
    of type 'T' that get their own protected space and set of methods.

    For example, if 'A' and 'B' are variable of type 'T' then you would
    say

    A.get(...)
    B.get(...)

    The data contained in 'A' and 'B' are totally separate from each
    other, so you might not need arrays of the same type. Or to put it
    another way, if 'A' and 'B' do need to know about the contents of the
    other in a rather detailed way, protected types might not be the best
    way to do whatever it is you're trying to do.

    Kevin Jennings
     
    KJ, Jul 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    2
    Views:
    590
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    564
    Henry S. Thompson
    Dec 1, 2005
  3. Jeremy Cowles

    STD types vs C++ intrinsic types

    Jeremy Cowles, Aug 18, 2003, in forum: C++
    Replies:
    5
    Views:
    1,888
    Bob Jacobs
    Aug 19, 2003
  4. Steve Knight
    Replies:
    2
    Views:
    761
    Steve Knight
    Oct 10, 2003
  5. Manlio Perillo

    missing types in module types?

    Manlio Perillo, May 29, 2004, in forum: Python
    Replies:
    0
    Views:
    354
    Manlio Perillo
    May 29, 2004
Loading...

Share This Page