comp.lang.ada
 help / color / mirror / Atom feed
* Problem with indefinite discriminant records in container
@ 2014-08-05 13:06 john
  2014-08-05 16:05 ` Simon Wright
  0 siblings, 1 reply; 4+ messages in thread
From: john @ 2014-08-05 13:06 UTC (permalink / raw)


I want to store records of different size in Ada.Containers.Indefinite_Vectors:

 type Rt_Class (Method_Table_Size : MethodId;
                  Superclass_Count  : ClassId) is record
      Id              : ClassId;
      Is_Interface    : Boolean;
      Methods         : Rt_Methods (1 .. Method_Table_Size);
      Superclasses    : Rt_Class_Ids (1 .. Superclass_Count);
      Inst_Prop_Count : Natural;
      Method_Count    : Natural;
   end record;

   package Class_Vectors is new Ada.Containers.Indefinite_Vectors
     (Index_Type => ClassId,
      Element_Type => Rt_Class);
   use Class_Vectors;
   type Rt_Classes is new Class_Vectors.Vector with null record;

it compiles but I get a *runtime* error "instantiation error" with explanation 
"invalid constraint: type has no discriminant" when the above package is instantiated.

Rt_Methods and Rt_Class_Ids are array types and all of this occurs in the private part of a package. 

How can I store different versions of an indefinite record with discriminants such as Rt_Class in some array or vector? Using access types would be very hard if not impossible in this case because of the associated scope restrictions. Somewhat annoying in this case is also that this table/array only needs to be created *once* in the beginning of program execution and otherwise is completely static and read-only ... and access should be as fast as possible.

Any ideas or suggestions?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with indefinite discriminant records in container
  2014-08-05 13:06 Problem with indefinite discriminant records in container john
@ 2014-08-05 16:05 ` Simon Wright
  2014-08-05 18:17   ` john
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Wright @ 2014-08-05 16:05 UTC (permalink / raw)


john@peppermind.com writes:

> How can I store different versions of an indefinite record with
> discriminants such as Rt_Class in some array or vector?

You should be able to do this. I made a compilable program with
mocked-up versions of the omitted types, and it compiles and runs with
every version of GNAT I have here.

with Ada.Containers.Indefinite_Vectors;
procedure John is

   subtype Methodid is Natural range 0 .. 10;
   subtype Classid is Natural range 0 .. 10;
   type Rt_Methods is array (Natural range <>) of Integer;
   type Rt_Class_Ids is array (Natural range <>) of Integer;

   type Rt_Class (Method_Table_Size : MethodId;
                  Superclass_Count  : ClassId)
     is record
        Id              : ClassId;
        Is_Interface    : Boolean;
        Methods         : Rt_Methods (1 .. Method_Table_Size);
        Superclasses    : Rt_Class_Ids (1 .. Superclass_Count);
        Inst_Prop_Count : Natural;
        Method_Count    : Natural;
     end record;

   package Class_Vectors is new Ada.Containers.Indefinite_Vectors
     (Index_Type => ClassId,
      Element_Type => Rt_Class);
   use Class_Vectors;
   type Rt_Classes is new Class_Vectors.Vector with null record;

   C :  Rt_Classes;

begin
   C.Append (Rt_Class'(Method_Table_Size => 1,
                       Superclass_Count => 1,
                       Id => 4,
                       Is_Interface => False,
                       Methods => (1 => 42),
                       Superclasses => (1 => 43),
                       Inst_Prop_Count => 44,
                       Method_Count => 45));
end John;

========================================================================

On a separate front, it seems to me that

   use Class_Vectors;
   type Rt_Classes is new Class_Vectors.Vector with null record;

are nudging the edge of current GNAT; indexing on the LHS, eg
   C (0) := ...
confused the heck out of the compiler, in differing ways for GNAT GPL
2014 and FSF GCC 4.9.0; something to do with Cursors, I think.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with indefinite discriminant records in container
  2014-08-05 16:05 ` Simon Wright
@ 2014-08-05 18:17   ` john
  2014-08-06 10:58     ` G.B.
  0 siblings, 1 reply; 4+ messages in thread
From: john @ 2014-08-05 18:17 UTC (permalink / raw)


Your completed example compiles and runs without error on my machine, too. I'm using FSF gcc 4.6.

So the error in my (fairly complex) program must come from elsewhere, though it definitely occurs at runtime when the package Class_Vectors is instantiated. Weird. I'll have to investigate this further.

Thanks a lot for your help!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with indefinite discriminant records in container
  2014-08-05 18:17   ` john
@ 2014-08-06 10:58     ` G.B.
  0 siblings, 0 replies; 4+ messages in thread
From: G.B. @ 2014-08-06 10:58 UTC (permalink / raw)


On 05.08.14 20:17, john@peppermind.com wrote:
> Your completed example compiles and runs without error on my machine, too. I'm using FSF gcc 4.6.
>
> So the error in my (fairly complex) program must come from elsewhere, though it definitely occurs at runtime when the package Class_Vectors is instantiated. Weird. I'll have to investigate this further.

FWIW, maybe adding -gnatE makes a difference?




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-06 10:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-05 13:06 Problem with indefinite discriminant records in container john
2014-08-05 16:05 ` Simon Wright
2014-08-05 18:17   ` john
2014-08-06 10:58     ` G.B.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox