comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Problem with indefinite discriminant records in container
Date: Tue, 05 Aug 2014 17:05:34 +0100
Date: 2014-08-05T17:05:34+01:00	[thread overview]
Message-ID: <lymwbiq5v5.fsf@pushface.org> (raw)
In-Reply-To: 986b5653-f446-4833-9a83-426f45b7c03f@googlegroups.com

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.

  reply	other threads:[~2014-08-05 16:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 13:06 Problem with indefinite discriminant records in container john
2014-08-05 16:05 ` Simon Wright [this message]
2014-08-05 18:17   ` john
2014-08-06 10:58     ` G.B.
replies disabled

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