Problems with Access types

T

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?
 
On Jul 18, 5:41 am, Tricky <Trickyh...@gmail.com> 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
 

Welcome to EDABoard.com

Sponsor

Back
Top