comp.lang.ada
 help / color / mirror / Atom feed
* Error Instantiating Child (very long)
@ 1996-08-07  0:00 Captain Earl Conrad Pilloud
  1996-08-08  0:00 ` Bruce Duncan
  0 siblings, 1 reply; 2+ messages in thread
From: Captain Earl Conrad Pilloud @ 1996-08-07  0:00 UTC (permalink / raw)



Hi,

I have an application where I need to define a number of child classes
(representing different attributes)
which are only slighly different from the parent class (Attribute).

I defined a tagged type which represents the parent.
(WW.Attribute.Object)
In a child package, I defined a generic package for the child class.
(WW.Attribute.Child)

My problem is that when I try to instantiate the generic child,
the parent class attributes are no longer visible.

package WW.Attribute.Sample is new Attribute.Child(
  Attribute_ID   => 3, 
  Attribute_Name => WW.Types.String16.To_Bounded_String("Sample"),
  T              => WW.Types.Vector_32, 
  T_Ptr          => WW.Types.Vector_32_Ref);
  

(This works if I make the child class non-generic, but I really don't
want to make .ads and .adb files for every different kind of child
class--that's what generics are for)

What's My Problem???? 

Thanks In Advance,
Conrad

  Source Code Follows Below....

(I'm compiling on the SGI using GNAT 3.04w with gcc 2.7.2)




ERROR REPORT



(comp is my compilation script)

prompt% comp ww-attribute-sample.ads
Reading specs from /usr/local/lib/gcc-lib/mips-sgi-irix5.3/2.7.2/specs
gcc version 2.7.2
 /usr/local/lib/gcc-lib/mips-sgi-irix5.3/2.7.2/gnat1 -I/usr/adainclude -I/usr/adainclude/net -I/usr/adainclude/netinet -I/usr/adainclude/sys -I../../booch -quiet -dumpbase ww-attribute-sample.ads -g -gnatevf ww-attribute-sample.ads -o /var/tmp/cca001NM.s

GNAT Compiler Version 3.04w Copyright 1995 Free Software Foundation, Inc.

Compiling: ww-attribute-sample.ads (source file time stamp: 1996-08-07 17:00:19)

==============Error messages for source file: ww-attribute-child.adb
    88.       Instance.ID   := Attribute_ID;
                      |
        >>> error: undefined selector for type "Object" defined at ww-attribute-child.ads:135

    89.       Instance.Name := Attribute_Name;
                      |
        >>> error: undefined selector for type "Object" defined at ww-attribute-child.ads:135

 75 lines: 2 errors


SOURCE CODE (use gnatchop)


------------------------------------------------------------------------
--
--
--              Air Force Institute of Technology (AFIT)
--                       School of Engineering
--         Department of Electrical and Computer Engineering
--            Division of Computer Science and Engineering
--
--                Software Engineering and Graphics Lab
--
--  This source code is distributed in the hope that it will be useful,
--  but without any warranty; without even the implied warranty of
--  quality or fitness for a particular purpose.
--
--  This source code is free software.  You can redistribute it as long
--  as this AFIT header and the README files are still in place.  You
--  can modify the software as long as the modified files have prominent
--  notices stating what has been changed from the original source 
--  files.
--  You can include our source code provided no intent of profit and you
--  clearly demonstrate that AFIT provided the software.
--
--  The Ada source code is yours to use.  If you develop any
--  publications based on our efforts, please send us a copy as we are 
--  interested in any work related to our system.  Be sure to reference 
--  the appropriate AFIT project(s) in your publications.
--
--  If you find (and fix) any bugs in our software, please let us know
--  so that everyone can be made aware of the bug and/or solution.  We 
--  would a also like to know if you modify our software and make 
--  improvements.  We may incorporate those changes into our next 
--  versions, giving credit to all who have helped.  You can send these
--  notices to AFIT via our mailing address or via our e-mail address.
--
--  The mailing address for the AFIT is:
--
--      Computer Graphics Lab
--      AFIT/ENG
--      Building 640
--      2950 P Street
--      Wright-Patterson AFB, OH  45433-7765
--
--  The e-mail addresses for the Ada developers in the Graphics Lab for
--  1996 are:
--
--      mkanko@afit.af.mil      Maj Mark Kanko, PhD, Faculty Advisor
--      epilloud@afit.af.mil    Capt Earl Conrad Pilloud,
--                                Student Researcher
--
------------------------------------------------------------------------
--
--  FILENAME: ww.ads
--
--  CREATION DATE: 06 Aug 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: None
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     06 Aug 96 - This is the top level package for the 
--                 WorldWise Application Framework.
--                 It contains WorldWise global definitions and anchors
--                 the application framework to a single point in the
--                 Ada library.
--
--  HISTORY:
--     06 Aug 96 - Created original version.
--
------------------------------------------------------------------------

package WW is 

   -- Global exceptions will be declared here.

   -- currently unused
   Placeholder_Violation : exception;

end WW;
------------------------------------------------------------------------
--
--  FILENAME: ww-types.ads
--
--  CREATION DATE: 06 Jun 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: No Specific Design Element
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     06 Jun 96 - This package contains some WorldWise-wide types.
--               -   this package is meant as a sort of "one stop shop"
--               -   for numeric portability.
--
--  HISTORY:
--     06 Jun 96 - Created original version.
--     25 Jun 96 - "Cleaned Up" commenting and adherance to coding 
--                   standards.
--               - Split into a common types package and a DIS-specific
--                   package (DIS_Types).
--     06 Aug 96 - Placed under package WW
--
------------------------------------------------------------------------

with Interfaces;
with Ada.Strings.Bounded;
with Ada.Calendar;

package WW.Types is


   ---------------------------------------------------------------------
   -- Common Constants

   ---------------------------------------------------------------------
   -- Common Generic Instantiations
   package String16 is new 
     Ada.Strings.Bounded.Generic_Bounded_Length(16);

  
   ---------------------------------------------------------------------
   -- Common Types

   type Int8  is new Interfaces.Integer_8;
   type Nat8  is new Interfaces.Unsigned_8;
   type Int16 is new Interfaces.Integer_16;
   type Nat16 is new Interfaces.Unsigned_16;
   type Int32 is new Interfaces.Integer_32;
   type Nat32 is new Interfaces.Unsigned_32;
   type Flt32 is new float;
   type Flt64 is new long_float;

   type Int8_Ref  is access all Nat8;
   type Nat8_Ref  is access all Nat8;
   type Int16_Ref is access all Nat32;
   type Nat16_Ref is access all Nat32;
   type Int32_Ref is access all Nat32;
   type Nat32_Ref is access all Nat32;
   type Flt32_Ref is access all Nat32;
   type Flt64_Ref is access all Nat32;


   ---------------------------------------------------------------------
   -- HLA-Like Definitions

   type Object_Class is new Interfaces.Unsigned_16;
   type Object_ID    is new Interfaces.Unsigned_32;

   type Interaction_Class is new Interfaces.Unsigned_16;
   type Interaction_ID    is new Interfaces.Unsigned_32;

   type Attribute_Name is new Interfaces.Unsigned_16;

   type Query_Type is new Interfaces.Unsigned_16;
   
   type Federation_Time is new Ada.Calendar.Time;

   ---------------------------------------------------------------------
   -- Common aggregate types

   type Flt32_Matrix is array (0..2, 0..2) of Flt32;

   type Flt32_Matrix_Ref is access all Flt32_Matrix;

   type Flt64_Matrix is array (0..2, 0..2) of Flt64;

   type Flt64_Matrix_Ref is access all Flt64_Matrix;

   type Vector_64 is
      record
         X : Flt64;
         Y : Flt64;
         Z : Flt64;
      end record;

   for Vector_64 use
      record
         X at 0 range 0..63;
         Y at 8 range 0..63;
         Z at 16 range 0..63;
      end record;

   type Vector_64_Ref is access all Vector_64;

   type Vector_32 is
      record
         X : Flt32;
         Y : Flt32;
         Z : Flt32;
      end record;

   for Vector_32 use
      record
         X at 0 range 0..31;
         Y at 4 range 0..31;
         Z at 8 range 0..31;
      end record;

   type Vector_32_Ref is access all Vector_32;

   type Euler_Angles_Type is
      record
         Psi   : Flt32;
         Theta : Flt32;
         Phi   : Flt32;
      end record;

   for Euler_Angles_Type use
      record
         Psi   at 0 range 0..31;
         Theta at 4 range 0..31;
         Phi   at 8 range 0..31;
      end record;

   type Euler_Angles_Type_Ref is access all Euler_Angles_Type;


end WW.Types;
------------------------------------------------------------------------
--
--  FILENAME: ww-attribute.ads
--
--  CREATION DATE: 17 Jul 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: WorldWise Attribute Class
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     17 Jul 96 - This package defines the base Attribute Class.
--
--  HISTORY:
--     17 Jul 96 - Created original version.
--     06 Aug 96 - Placed under WW package hierarchy
--
------------------------------------------------------------------------
with WW.Types;
with Ada.Finalization;

package WW.Attribute is

   -- LIMITATION
   -- Objects May have up to 16 attributes

   subtype Attribute_Index is WW.Types.Attribute_Name range 0..15;

   type Object is new Ada.Finalization.Controlled with private;

   type Reference is access all Object'Class;

   type Attribute_Array is array (Attribute_Index'First ..
     Attribute_Index'Last) of Reference;

   ---------------------------------------------------------------------
   -- Automatically called upon allocation of Object
   ---------------------------------------------------------------------
   procedure Initialize(Instance : in out Object);

   ---------------------------------------------------------------------
   -- Automatically called upon assignment to Object
   ---------------------------------------------------------------------
   procedure Adjust(Instance: in out Object);

   ---------------------------------------------------------------------
   -- Automatically called upon destruction of Object
   ---------------------------------------------------------------------
   procedure Finalize(Instance : in out Object);

   ---------------------------------------------------------------------
   -- Delete a dynamically allocated object
   --   (a dispatching subprogram)
   ---------------------------------------------------------------------
   procedure Delete(Instance : access Object);

   ---------------------------------------------------------------------
   -- Return the Attribute's ID
   --   (a class-wide subprogam)
   ---------------------------------------------------------------------
   function Get_ID(Instance : Reference)
     return Attribute_Index;
   pragma Inline(Get_ID);

   ---------------------------------------------------------------------
   -- Return the Attribute's Name
   --   (a class-wide subprogam)
   ---------------------------------------------------------------------
   function Get_Name(Instance : Reference)
     return WW.Types.String16.Bounded_String;
   pragma Inline(Get_Name);

private

   type Object is new Ada.Finalization.Controlled with
      record
         ID   :  Attribute_Index := Attribute_Index'First;

         Name :  WW.Types.String16.Bounded_String := 
           WW.Types.String16.Null_Bounded_String;
      end record;


end WW.Attribute;
------------------------------------------------------------------------
--
--  FILENAME: ww-attribute.adb
--
--  CREATION DATE: 17 Jul 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: WorldWise Attribute Class
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     17 Jul 96 - This package defines the base Attribute Class.
--
--  HISTORY:
--     17 Jul 96 - Created original version.
--     06 Aug 96 - Placed under WW package hierarchy
--
------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;

package body WW.Attribute is

   type Delete_Object_Pointer is access all Object;

   procedure Destroy is new Ada.Unchecked_Deallocation(Object, 
     Delete_Object_Pointer);

   -- Null subprograms since there is nothing to de-allocate for
   --   the Base Attribute Class

   ---------------------------------------------------------------------
   -- Automatically called upon allocation of Object
   ---------------------------------------------------------------------
   procedure Initialize(Instance : in out Object) is
   begin
      null;
   end Initialize;


   ---------------------------------------------------------------------
   -- Automatically called upon assignment to Object
   ---------------------------------------------------------------------
   procedure Adjust(Instance: in out Object) is
   begin
      null;
   end Adjust;


   ---------------------------------------------------------------------
   -- Automatically called upon destruction of Object
   ---------------------------------------------------------------------
   procedure Finalize(Instance : in out Object) is
   begin
      null;
   end Finalize;


   ---------------------------------------------------------------------
   -- Delete a dynamically allocated object
   --   (a dispatching subprogram)
   ---------------------------------------------------------------------
   procedure Delete(Instance : access Object)is

      Dummy_Pointer : Delete_Object_Pointer := Instance;

   begin
      Destroy(Dummy_Pointer);
   end Delete;

   ---------------------------------------------------------------------
   -- Return the Attribute's ID
   --   (a class-wide subprogam)
   ---------------------------------------------------------------------
   function Get_ID(Instance : Reference) 
     return Attribute_Index is
   begin
      return Instance.ID;
   end Get_ID;

   ---------------------------------------------------------------------
   -- Return the Attribute's Name
   --   (a class-wide subprogam)
   ---------------------------------------------------------------------
   function Get_Name(Instance : Reference)
     return WW.Types.String16.Bounded_String is
   begin
      return Instance.Name;
   end Get_Name;


end WW.Attribute;
------------------------------------------------------------------------
--
--  FILENAME: ww-attribute-child.ads
--
--  CREATION DATE: 18 Jul 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: WorldWise Attribute Generic Child Class
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     18 Jul 96 - This package defines the Generic Attribute
--                   child class.
--
--  HISTORY:
--     18 Jul 96 - Created original version.
--     06 Aug 96 - Placed under the WW package hierarchy
--
------------------------------------------------------------------------
with WW.Types;

generic

   Attribute_ID   : Attribute_Index;
   Attribute_Name : WW.Types.String16.Bounded_String;

   type T is private;
   type T_Ptr is access all T;

package WW.Attribute.Child is


   type Object is new WW.Attribute.Object with private;

   type Reference is access all Object'Class;

   ---------------------------------------------------------------------
   -- Automatically called upon allocation of Object
   ---------------------------------------------------------------------
   procedure Initialize(Instance : in out Object);

   ---------------------------------------------------------------------
   -- Automatically called upon assignment to Object
   ---------------------------------------------------------------------
   procedure Adjust(Instance: in out Object);

   ---------------------------------------------------------------------
   -- Automatically called upon destruction of Object
   ---------------------------------------------------------------------
   procedure Finalize(Instance : in out Object);

   ---------------------------------------------------------------------
   -- Delete a dynamically allocated object
   ---------------------------------------------------------------------
   procedure Delete(Instance : access Object);


   ---------------------------------------------------------------------
   -- Get the Attribute's Value
   ---------------------------------------------------------------------
   function Get_Value(Instance : access Object)
     return T;
   pragma Inline(Get_Value);


   ---------------------------------------------------------------------
   -- Get a reference to the Attribute's Value
   ---------------------------------------------------------------------
   function Get_Pointer(Instance : access Object)
     return T_Ptr;
   pragma Inline(Get_Pointer);
  

   ---------------------------------------------------------------------
   -- Set the Attribute's Value
   ---------------------------------------------------------------------
   procedure Set_Value(
     Instance  : access Object;
     New_Value : in     T);
   pragma Inline(Set_Value);

private

   type Object is new WW.Attribute.Object with
      record
         Data : aliased T;
      end record;


end WW.Attribute.Child;
------------------------------------------------------------------------
--
--  FILENAME: ww-attribute-child.adb
--
--  CREATION DATE: 18 Jul 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: WorldWise Attribute Generic Child Class
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     18 Jul 96 - This package defines the Generic Attribute
--                   child class.
--
--  HISTORY:
--     18 Jul 96 - Created original version.
--     06 Aug 96 - Placed under WW package hierarchy
--
------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;

package body WW.Attribute.Child is

   type Delete_Object_Pointer is access all Object;

   procedure Destroy is new Ada.Unchecked_Deallocation(Object, 
     Delete_Object_Pointer);

   -- Null subprograms since there is nothing to de-allocate for
   --   the Base Attribute Class

   ---------------------------------------------------------------------
   -- Automatically called upon allocation of Object
   ---------------------------------------------------------------------
   procedure Initialize(Instance : in out Object) is
   begin
      Instance.ID   := Attribute_ID;
      Instance.Name := Attribute_Name;
   end Initialize;


   ---------------------------------------------------------------------
   -- Automatically called upon assignment to Object
   ---------------------------------------------------------------------
   procedure Adjust(Instance: in out Object) is
   begin
      null;
   end Adjust;


   ---------------------------------------------------------------------
   -- Automatically called upon destruction of Object
   ---------------------------------------------------------------------
   procedure Finalize(Instance : in out Object) is
   begin
      null;
   end Finalize;


   ---------------------------------------------------------------------
   -- Delete a dynamically allocated object
   ---------------------------------------------------------------------
   procedure Delete(Instance : access Object)is

      Dummy_Pointer : Delete_Object_Pointer := Instance;

   begin
      Destroy(Dummy_Pointer);
   end Delete;


   ---------------------------------------------------------------------
   -- Get the Attribute's Value
   ---------------------------------------------------------------------
   function Get_Value(Instance : access Object)
     return T is
   begin
      return Instance.Data;
   end Get_Value;


   ---------------------------------------------------------------------
   -- Get a reference to the Attribute's Value
   ---------------------------------------------------------------------
   function Get_Pointer(Instance : access Object)
     return T_Ptr is
   begin
      return Instance.Data'Access;
   end Get_Pointer;
  

   ---------------------------------------------------------------------
   -- Set the Attribute's Value
   ---------------------------------------------------------------------
   procedure Set_Value(
     Instance  : access Object;
     New_Value : in     T) is
   begin
      Instance.Data := New_Value;
   end Set_Value;

end WW.Attribute.Child;
------------------------------------------------------------------------
--
--  FILENAME: ww-attribute-sample.ads
--
--  CREATION DATE: 18 Jul 96
--
--  AUTHOR: Conrad Pilloud
--
--  DESIGN REFERENCE: WorldWise Sample Generic Instantiation
--
--  COMPILER VERSION:  GNAT 3.04w (SGI) using GCC 2.7.2
--
--  DESCRIPTION:
--     17 Jul 96 - This package defines the DIS Marking Attribute.
--
--  HISTORY:
--     17 Jul 96 - Created original version.
--     07 Aug 96 - Placed under WW package hierarchy
------------------------------------------------------------------------
with WW.Attribute.Child;

package WW.Attribute.Sample is new Attribute.Child(
  Attribute_ID   => 3, 
  Attribute_Name => WW.Types.String16.To_Bounded_String("Sample"),
  T              => WW.Types.Vector_32, 
  T_Ptr          => WW.Types.Vector_32_Ref);





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

* Re: Error Instantiating Child (very long)
  1996-08-07  0:00 Error Instantiating Child (very long) Captain Earl Conrad Pilloud
@ 1996-08-08  0:00 ` Bruce Duncan
  0 siblings, 0 replies; 2+ messages in thread
From: Bruce Duncan @ 1996-08-08  0:00 UTC (permalink / raw)



In article <4uals1$7s4@blackbird.afit.af.mil>,
Captain Earl Conrad Pilloud  <epilloud@afit.af.mil> wrote:
>Hi,
>
>I have an application where I need to define a number of child classes
>(representing different attributes)
>which are only slighly different from the parent class (Attribute).
>
>I defined a tagged type which represents the parent.
>(WW.Attribute.Object)
>In a child package, I defined a generic package for the child class.
>(WW.Attribute.Child)
>
>My problem is that when I try to instantiate the generic child,
>the parent class attributes are no longer visible.
>
>package WW.Attribute.Sample is new Attribute.Child(
>  Attribute_ID   => 3, 
>  Attribute_Name => WW.Types.String16.To_Bounded_String("Sample"),
>  T              => WW.Types.Vector_32, 
>  T_Ptr          => WW.Types.Vector_32_Ref);
>  
>
>(This works if I make the child class non-generic, but I really don't
>want to make .ads and .adb files for every different kind of child
>class--that's what generics are for)
>
>What's My Problem???? 

This looks like a compiler bug.

Our AdaMagic compiler says it's OK (well, with one unrelated
fix... see below).

>Thanks In Advance,
>Conrad
>
>  Source Code Follows Below....
>
>(I'm compiling on the SGI using GNAT 3.04w with gcc 2.7.2)

You should send this along to report@gnat.com to let them know of the
problem.

The other problem that the AdaMagic compiler found was that both of
your Delete routines need an explicit conversion from the anonymous
access type:

>   procedure Delete(Instance : access Object)is
>
>      Dummy_Pointer : Delete_Object_Pointer := Instance;

Should be:

  procedure Delete(Instance : access Object)is

     Dummy_Pointer : Delete_Object_Pointer := Delete_Object_Pointer(Instance);


If GNAT doesn't catch this then you should also report that as a bug.

-- Bruce Duncan (duncan@inmet.com)
-- Intermetrics, Inc.




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

end of thread, other threads:[~1996-08-08  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-07  0:00 Error Instantiating Child (very long) Captain Earl Conrad Pilloud
1996-08-08  0:00 ` Bruce Duncan

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