comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: limited agregate and limited components default initialization
Date: Sat, 31 Mar 2018 20:31:39 -0700 (PDT)
Date: 2018-03-31T20:31:39-07:00	[thread overview]
Message-ID: <452ef4be-7210-4aca-9c48-12be7f0e9b94@googlegroups.com> (raw)
In-Reply-To: <c49f7d08-5e8f-4f15-a85b-d734a552ca4d@googlegroups.com>

On Saturday, March 31, 2018 at 11:14:49 PM UTC-4, Jere wrote:
> On Saturday, March 31, 2018 at 10:07:20 PM UTC-4, Jean-Claude Rostaing wrote:
> >    type ITEM_ACCESS;
> >    type Item_Record is limited
> >       record
> >          Item: aliased Item_type;
> >          Next : Item_Access;
> >          Pred : Item_Access;
> >       end record;
> >    package Record_Pointers is new Pointers (Item_type => Item_Record);
> >    type Item_Access is new Record_Pointers.Smart_Pointers;
> 
> Side note:  I couldn't get this to compile because Next and Pred
> are incomplete types (so they too cannot be used a variable types.
> 
> The proper way to do it would be:
>        type Item_Record;
>        package Record_Pointers is new Pointers (Item_type => Item_Record);
>        type Item_Access is new Record_Pointers.Smart_Pointers; 
>     
>        type Item_Record is limited
>           record
>              Item : aliased Item_type;
>              Next : Item_Access;
>              Pred : Item_Access;
>           end record;
> 
> but your Pointers package will need an incomplete formal type for it to
> work:
> 
>     generic
>         type Item_Type(<>);
>     package Pointers is
>         -- stuff
>     end Pointers;
> 
> and that might cause you other problems, but if you want to use
> your smart pointers in a self referential type, you'll need your
> smart pointer generic to use incomplete types.

Since you didn't supply a minimally compilable example, I made a 
quick one stubbing in the things you didn't specify.  Hopefully
this will help give some ideas on what I mean:

procedure jdoodle is

    generic
        type Item_Type(<>);
    package Pointers is
        type Smart_Pointers is limited null record;
    end Pointers;

    generic
       type Item_Type is limited private;
       with function Make_Item return Item_Type;
    package Lists is
       type List_Type is limited private;
       type Item_Accessor (Item: not null access Item_type) is limited private with Implicit_Dereference => Item; 
       
       -- added stub
       type List_Iterator is limited record
            Ref : access Item_Type;
       end record;
       
       function Get(Position: in List_Iterator) return Item_Accessor;
    private
        type Item_Record;
        package Record_Pointers is new Pointers (Item_type => Item_Record);
        type Item_Access is new Record_Pointers.Smart_Pointers; 
    
       type Item_Record is limited
          record
             Item : aliased Item_type;
             Next : Item_Access;
             Pred : Item_Access;
          end record;
          
        -- Added stub
        function Set(value : Item_Record) return Item_Access is (others => <>);
       
        type Item_Accessor (Item: not null access Item_type) is limited record
            REF: ITEM_ACCESS := Set(Item_Record'(Make_Item, others => <>));
        end record;
        
        function Get(Position: in List_Iterator) return Item_Accessor is (Item => Position.Ref, others => <>);
       
       type List_Type is limited record
          First: Item_Access;
          Last : Item_Access;
          Count : Natural := 1;
        end record; 
    end lists;
    
    
    -----------------------------------------------------------
    -- Testing package instantiation
    -----------------------------------------------------------
    type Test is record
        value : Integer := 0;
    end record;
    function Make_Test return Test is (value => 10);
    
    package Test_Lists is new Lists(Item_Type => Test, Make_Item => Make_Test);
begin
    null;
end jdoodle;


  reply	other threads:[~2018-04-01  3:31 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-31 23:36 limited agregate and limited components default initialization Jean-Claude Rostaing
2018-04-01  0:52 ` Jere
2018-04-01  1:12   ` Jere
2018-04-01  1:16   ` Jean-Claude Rostaing
2018-04-01  1:34     ` Jere
2018-04-01  2:07       ` Jean-Claude Rostaing
2018-04-01  2:40         ` Jere
2018-04-01  2:54           ` Jere
2018-04-01  3:14         ` Jere
2018-04-01  3:31           ` Jere [this message]
2018-04-01  9:32         ` Jacob Sparre Andersen
2018-04-01 12:58           ` Jean-Claude Rostaing
2018-04-01 13:33 ` Dmitry A. Kazakov
2018-04-01 15:46   ` Jean-Claude Rostaing
2018-04-01 15:53     ` Jean-Claude Rostaing
2018-04-01 15:54       ` Jean-Claude Rostaing
2018-04-01 21:31       ` Dmitry A. Kazakov
2018-04-02  3:44         ` Randy Brukardt
2018-04-02 11:25           ` Jean-Claude Rostaing
2018-04-02 12:11             ` Dmitry A. Kazakov
2018-04-02 12:15             ` Jean-Claude Rostaing
2018-04-02 21:37             ` Randy Brukardt
2018-04-03 17:01               ` Jeffrey R. Carter
2018-04-05 10:27           ` AdaMagica
2018-04-02  3:42     ` Randy Brukardt
2018-04-01 22:52 ` Jean-Claude Rostaing
2018-04-01 23:36   ` Jean-Claude Rostaing
2018-04-01 23:39     ` Jean-Claude Rostaing
2018-04-02 18:19       ` Jere
2018-04-02 18:50         ` Dmitry A. Kazakov
2018-04-02 19:46           ` Jere
2018-04-02 19:59             ` Dmitry A. Kazakov
2018-04-02 21:03               ` Jean-Claude Rostaing
2018-04-03  8:14                 ` Dmitry A. Kazakov
2018-04-03  1:27             ` Dennis Lee Bieber
2018-04-02 22:39     ` Robert I. Eachus
2018-04-03 18:18 ` Jean-Claude Rostaing
2018-04-03 18:28   ` Jean-Claude Rostaing
2018-04-03 19:18   ` Jeffrey R. Carter
2018-04-03 19:25     ` Jean-Claude Rostaing
2018-04-03 20:12       ` Jeffrey R. Carter
2018-04-03 22:37         ` Jean-Claude Rostaing
2018-04-04  2:18   ` Jere
replies disabled

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