Problems with Access types

T

Tricky

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?
 
K

KJ

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;

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top