comp.lang.ada
 help / color / mirror / Atom feed
From: b.mcguinness747@gmail.com
Subject: Having problems instantiating a child class with an extension aggregate
Date: Sun, 26 Jan 2020 16:22:11 -0800 (PST)
Date: 2020-01-26T16:22:11-08:00	[thread overview]
Message-ID: <79386e8a-20cb-4bcb-a60a-531919ee6976@googlegroups.com> (raw)


I have three packages:

--------------------------------------------------------------------------------
-- Basic data types used by other packages
--------------------------------------------------------------------------------
package APL_Types is
  ...

  type    Int64    is       range -9223372036854775808..9223372036854775807;
  subtype Int32    is Int64 range -2147483648..2147483647;
  subtype Int16    is Int64 range -32768..32767;

  subtype APL_Integer is Int64;

  ...

  type    Array_Index is range 0..APL_Integer'Last;

  type    Index_List         is array(Array_Index range <>) of Array_Index;
  type    Index_List_Pointer is access Index_List;

  procedure Free_Index_List is new Ada.Unchecked_Deallocation (Index_List, Index_List_Pointer);

  subtype Dimensions         is Index_List;
  type    Dimensions_Pointer is access Dimensions;

  procedure Free_Dimensions is new Ada.Unchecked_Deallocation (Dimensions, Dimensions_Pointer);

  ...
end APL_Types;


--------------------------------------------------------------------------------
-- This holds the dimensions of the array, which can change over time
--
-- The array elements are handled by child classes since they might either be
-- stored in the array or calculated when required.
--------------------------------------------------------------------------------
with Ada.Finalization;
with APL_Types;

package APL_Arrays is
  use APL_Types;

  type APL_Array         is new Ada.Finalization.Controlled with private;
  type APL_Array_Pointer is access APL_Array;

  function  Effective_Rank (array_rank, function_rank : Array_Index) return Array_Index;

  procedure Finalize (this : in out APL_Array);

  function  Length         (this : in APL_Array; axis : Array_Index) return Array_Index;
  function  Rank           (this : in APL_Array) return Array_Index;
  function  Raveled_Length (this : in APL_Array) return Array_Index;

  function  Raveled_Shape (
    shape         : Dimensions; 
    function_rank : Array_Index; 
    to_table      : in Boolean := false
  ) return Dimensions_Pointer;

  function  Same_Shape  (this, other : in APL_Array) return Boolean;

private
  type APL_Array is new Ada.Finalization.Controlled with record
    g_shape : Dimensions_Pointer;
  end record;
end APL_Arrays;


--------------------------------------------------------------------------------
-- Arrays that store each array element
--------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with APL_Arrays, APL_Types;

generic
  type Element is private;

package APL_Data_Arrays is
  use APL_Types;

  type APL_Data_Array          is new APL_Arrays.APL_Array with private;
  type APL_Data_Array_Pointer  is access APL_Data_Array;

  type Scalar_Monadic_Function is access function (right : Element) return Element;
  type Scalar_Dyadic_Function  is access function (left, right : Element) return Element;

  function Apply_Scalar_Dyadic (
    left,  right : in APL_Data_Array;      -- The arrays to be operated on
    lrank, rrank : Array_Index;            -- The left and right function rank
    fn           : Scalar_Dyadic_Function  -- Function to apply to the arrays
  ) return APL_Data_Array_Pointer;

  function Apply_Scalar_Monadic (
    right : in APL_Data_Array;       -- The array to be operated on
    fn    : Scalar_Monadic_Function  -- The function to apply to the array
  ) return APL_Data_Array_Pointer;

  procedure Finalize (this : in out APL_Data_Array);

  overriding function Raveled_Length (this : in APL_Data_Array) return Array_Index;

private
  use APL_Types;

  type Elements is array(Array_Index range <>) of Element;
  type Elements_Pointer is access Elements;

  procedure Free_Elements is new Ada.Unchecked_Deallocation (Elements, Elements_Pointer);

  type APL_Data_Array is new APL_Arrays.APL_Array with record
    g_data : Elements_Pointer;
  end record;
end APL_Data_Arrays;



I am trying to create instances of APL_Data_Array in apl_data_arrays.adb.  I have procedures that perform operations on one or two arrays and generate a third array with the same dimensions as one of the original arrays, so I want to create a result array, copying the dimensions from an existing array and allocating space for the array elements to be calculated.  I tried:

    result : APL_Data_Array_Pointer := new APL_Data_Array'(
               g_shape => new Dimensions'(right.g_shape.all),
               g_data  => new Elements(right.g_data.all'Range)
             );


This gives me an error message:

apl_data_arrays.adb:180:36: type of aggregate has private ancestor "Controlled"
apl_data_arrays.adb:180:36: must use extension aggregate


But when I try:

    result : APL_Data_Array_Pointer := new APL_Data_Array'(
               APL_Array'(new Dimensions'(right.g_shape.all)) with
               g_data  => new Elements(right.g_data.all'Range)
             );


I get another error message:

apl_data_arrays.adb:180:48: no selector "g_shape" for type "APL_Data_Array" defined at apl_data_arrays.ads:46

This puzzles me since g_shape is a member of the parent class and should be visible to the child class.  I don't see how to fix the problem.

I would appreciate help.

--- Brian McGuinness

             reply	other threads:[~2020-01-27  0:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-27  0:22 b.mcguinness747 [this message]
2020-01-27  1:04 ` Having problems instantiating a child class with an extension aggregate Jere
2020-01-27 17:47 ` Simon Wright
2020-01-27 23:08 ` b.mcguinness747
replies disabled

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