Reputation: 25350
I have some trouble with the definition of a generic record:
-- ADS File
package Stack is
-- (generic) Entry
generic type StackEntry is private;
-- An array of Entries (limited to 5 for testing)
type StackEntryHolder is array (0..5) of StackEntry;
-- Stack type containing the entries, it's max. size and the current position
type StatStack is
record -- 1 --
maxSize : Integer := 5; -- max size (see above)
pos : Integer := 0; -- current position
content : StackEntryHolder; -- content entries
end record;
-- functions / procedures
end Stack;
If i compile this i get the following error (at -- 1 --
):
record not allowed in generic type definition
Upvotes: 0
Views: 1852
Reputation: 44804
That's because the code you wrote doesn't follow the proper syntax for a generic declaration. You can view this in its glorious BNF form in the LRM.
Basically, you have to decide if you want to declare a generic package or a generic routine. Guessing you want more that just a single subroutine generic, I'll assume you want a package. Given that it should look something like:
generic
{generic formal stuff} {package declaration}
...where "{package declaration}" is just a normal package delcaration (but one that may use stuff declared in the generic formal part), and "{generic formal stuff}" is a series of delcarations of generic "formal" parameters that the client will pass into the generic.
What happened in your code is that the compiler sees the magic word generic
and is now expecting everything up until the next subprogram or package delcaration will be generic formal parameters. The first one it finds, the private type delcaration on the same line, is just fine. However, the next line contains a full record declaration, which doesn't look like a generic formal parameter at all. So the compiler got confused and spit out an error.
Upvotes: 3
Reputation:
I think you are looking for something more like this:
generic
type StackEntry is private;
package Stack_G is
type ReturnCode is (Ok,Stack_Full,Stack_Empty);
-- functions / procedures
procedure Push (E : in StackEntry;
RC : out ReturnCode);
procedure Pop (E : out StackEntry;
RC : out ReturnCode);
private
-- An array of Entries (limited to 5 for testing)
type StackIndex is new Integer range 1 .. 5;
type StackEntryHolder is array (StackIndex) of StackEntry;
-- Stack type containing the entries, it's max. size and the current position
type StatStack is record
IsEmpty : Boolean := True;
Pos : StackIndex := StackIndex'First;-- current position
Content : StackEntryHolder; -- content entries
end record;
end Stack_G;
Upvotes: 3
Reputation:
I think you want to make a generic package that supplies a private type StatStack and its operations.
Upvotes: 3