comp.lang.ada
 help / color / mirror / Atom feed
* Why can't I override these functions?
@ 2004-05-07 10:43 Björn Persson
  2004-05-07 17:15 ` Jim Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-07 10:43 UTC (permalink / raw)


I have a generic package with a tagged type Parameter_Definition, a 
generic subpackage with a type Intermediate_Definition derived from 
Parameter_Definition, and a generic child package with a type 
Typed_Parameter_Definition derived from Intermediate_Definition. See the 
code below. Gnat gives me an error on the declaration of 
Typed_Parameter_Definition:

extracted-discrete_parameters.ads:19:09: type must be declared abstract 
or "Meaning" overridden

But I *have* overridden that function! It's right there on line 23! If I 
take Meaning away I get the same error saying that Default must be 
overridden, which I have also done. I must be stupid because I can't see 
why these functions don't count as overriding. Either that or the error 
message is misleading and the error is really something else. Could 
somebody please explain this?


Here's the code. I have removed lots of stuff that doesn't affect the 
error message:


with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

generic
    type Parameter_Name is (<>);
package Extracted is


private

    type Parameter_Definition(mandatory, multiple : boolean) is
      abstract tagged record
       Description : Unbounded_String;
    end record;
    type Parameter_Definition_Pointer is access all 
Parameter_Definition'class;

    type Value_Wrapper is tagged null record;
    type Value_Wrapper_Pointer is access all Value_Wrapper'class;


    function Meaning(Def : Parameter_Definition;
                     Name : Parameter_Name;
                     Text : Unbounded_String)
                     return Value_Wrapper_Pointer is abstract;

    function Meaning_Valueless(Def : Parameter_Definition;
                               Name : Parameter_Name)
                               return Value_Wrapper_Pointer;

    function Default(Def : Parameter_Definition)
                     return Value_Wrapper_Pointer is abstract;


    --
    -- Common_Functions
    --

    generic
       type Value_Type is private;
       type Array_Type is array(positive range <>) of Value_Type;
       type Wrapper_Type is new Value_Wrapper with private;
       with function Content(Wrapper : Wrapper_Type) return Value_Type;
    package Common_Functions is

       type Intermediate_Definition(mandatory, multiple : boolean) is
       abstract new Parameter_Definition(mandatory, multiple) with record
          case mandatory is
             when false =>
                case multiple is
                   when false =>
                      Default : Value_Type;
                   when true =>
                      null;
                end case;
             when true =>
                null;
          end case;
       end record;

    end Common_Functions;

end Extracted;


with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

generic
    type The_Type is (<>);
package Extracted.Discrete_Parameters is

    type Vector is array(Positive range <>) of The_Type;

private
    type Typed_Wrapper is new Value_Wrapper with record
       Value : The_Type;
    end record;

    function Content(Wrapper : Typed_Wrapper) return The_Type;

    package Funcs is new Common_Functions
      (The_Type, Vector, Typed_Wrapper, Content);
                  -- This is line 18. Error on line 19 below. ---------
    type Typed_Parameter_Definition(mandatory, multiple : boolean) is
      new Funcs.Intermediate_Definition(mandatory, multiple) with
      null record;

    function Meaning(Def : Typed_Parameter_Definition;  -- line 23
                     Name : Parameter_Name;
                     Text : Unbounded_String)
                     return Value_Wrapper_Pointer;

    function Default(Def : Typed_Parameter_Definition)
                     return Value_Wrapper_Pointer;

end Extracted.Discrete_Parameters;

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-07 10:43 Why can't I override these functions? Björn Persson
@ 2004-05-07 17:15 ` Jim Rogers
  2004-05-07 18:15   ` Björn Persson
  2004-05-07 18:42 ` Georg Bauhaus
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Jim Rogers @ 2004-05-07 17:15 UTC (permalink / raw)


Bj�rn Persson <spam-away@nowhere.nil> wrote in message news:<HLJmc.58389$mU6.237165@newsb.telia.net>...
> I have a generic package with a tagged type Parameter Definition, a 
> generic subpackage with a type Intermediate Definition derived from 
> Parameter Definition, and a generic child package with a type 
> Typed Parameter Definition derived from Intermediate Definition. See the 
> 
> code below. Gnat gives me an error on the declaration of 
> Typed Parameter Definition:
> 

Ada identifiers cannot contain blanks. For instance "Parameter Definition"
cannot be an identifier. Try inserting underscore characters where you
currently have spaces, such as "Parameter_Definition".

Jim Rogers



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

* Re: Why can't I override these functions?
  2004-05-07 17:15 ` Jim Rogers
@ 2004-05-07 18:15   ` Björn Persson
  0 siblings, 0 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-07 18:15 UTC (permalink / raw)


Jim Rogers wrote:

> Ada identifiers cannot contain blanks. For instance "Parameter Definition"
> cannot be an identifier. Try inserting underscore characters where you
> currently have spaces, such as "Parameter_Definition".

It looks like you're reading Usenet through Google. I suggest that you 
ask the Google staff to stop replacing underscores with spaces, or get 
yourself a newsreader that doesn't mangle the messages.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-07 10:43 Why can't I override these functions? Björn Persson
  2004-05-07 17:15 ` Jim Rogers
@ 2004-05-07 18:42 ` Georg Bauhaus
  2004-05-07 19:38   ` Björn Persson
  2004-05-10 11:49 ` Martin Dowie
  2004-05-13  7:23 ` Björn Persson
  3 siblings, 1 reply; 13+ messages in thread
From: Georg Bauhaus @ 2004-05-07 18:42 UTC (permalink / raw)


Bj�rn Persson <spam-away@nowhere.nil> wrote:
 
: extracted-discrete_parameters.ads:19:09: type must be declared abstract 
: or "Meaning" overridden

FWIW, two things remove the complaint:
1/ removing private-ness
2/ inserting the child unit after Common_Functions as a subpackage


-- Georg



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

* Re: Why can't I override these functions?
  2004-05-07 18:42 ` Georg Bauhaus
@ 2004-05-07 19:38   ` Björn Persson
  2004-05-08  6:15     ` Martin Krischik
  2004-05-08 11:34     ` Simon Wright
  0 siblings, 2 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-07 19:38 UTC (permalink / raw)


Georg Bauhaus wrote:

> Björn Persson <spam-away@nowhere.nil> wrote:
>  
> : extracted-discrete_parameters.ads:19:09: type must be declared abstract 
> : or "Meaning" overridden
> 
> FWIW, two things remove the complaint:
> 1/ removing private-ness

Hmm, yes. And I only have to remove private-ness in the parent package. 
How odd. (As if the whole thing weren't extremely odd already.)

I want to avoid that of course. I would rather eliminate 
Intermediate_Definition and derive directly from Parameter_Definition 
(which also removes the complaint). It would increase code duplication, 
but that's preferrable to making things public that should be private.

> 2/ inserting the child unit after Common_Functions as a subpackage

Well, I can do that only if I also remove private-ness, since 
Discrete_Parameters must be publicly visible.

Thanks anyway.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-07 19:38   ` Björn Persson
@ 2004-05-08  6:15     ` Martin Krischik
  2004-05-09 12:42       ` Björn Persson
  2004-05-08 11:34     ` Simon Wright
  1 sibling, 1 reply; 13+ messages in thread
From: Martin Krischik @ 2004-05-08  6:15 UTC (permalink / raw)


Bjï¿œrn Persson wrote:

> Georg Bauhaus wrote:
> 
>> Bjï¿œrn Persson <spam-away@nowhere.nil> wrote:
>>  
>> : extracted-discrete_parameters.ads:19:09: type must be declared abstract
>> : or "Meaning" overridden
>> 
>> FWIW, two things remove the complaint:
>> 1/ removing private-ness
> 
> Hmm, yes. And I only have to remove private-ness in the parent package.
> How odd. (As if the whole thing weren't extremely odd already.)

It is not odd. When the keyword "tagged" is only inside the private section
then the "tag is hidden". Only child packages can see the tag and can
extend the class.

Remember, you can split the type into two parts: A partial public
specification and a full private specification.

> I want to avoid that of course. I would rather eliminate
> Intermediate_Definition and derive directly from Parameter_Definition
> (which also removes the complaint). It would increase code duplication,
> but that's preferrable to making things public that should be private.

The partial pubic and full private specification can inherit from different
classes of the same class hirachie.

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Why can't I override these functions?
  2004-05-07 19:38   ` Björn Persson
  2004-05-08  6:15     ` Martin Krischik
@ 2004-05-08 11:34     ` Simon Wright
  2004-05-09 12:38       ` Björn Persson
  1 sibling, 1 reply; 13+ messages in thread
From: Simon Wright @ 2004-05-08 11:34 UTC (permalink / raw)


The compiler should probably have said something to point you at:

   AARM 3.9.3(10), For an abstract type declared in a visible part, an
   abstract primitive subprogram shall not be declared in the private
   part, unless it is overriding an abstract subprogram implicitly
   declared in the visible part. For a tagged type declared in a
   visible part, a primitive function with a controlling result shall
   not be declared in the private part, unless it is overriding a
   function implicitly declared in the visible part.

   Reason: The ``visible part'' could be that of a package or a
   generic package. This rule is needed because a non-abstract type
   extension declared outside the package would not know about any
   abstract primitive subprograms or primitive functions with
   controlling results declared in the private part, and wouldn't know
   that they need to be overridden with non-abstract subprograms. The
   rule applies to a tagged record type or record extension declared
   in a visible part, just as to a tagged private type or private
   extension. The rule applies to explicitly and implicitly declared
   abstract subprograms:

In an equivalent place in the Booch Components, I make the subprogram
concrete and say

   function Item_At (C : Container; Index : Positive) return Item_Ptr is
   begin
      raise Should_Have_Been_Overridden;
      return null;
   end Item_At;

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: Why can't I override these functions?
  2004-05-08 11:34     ` Simon Wright
@ 2004-05-09 12:38       ` Björn Persson
  2004-05-10  5:43         ` Simon Wright
  0 siblings, 1 reply; 13+ messages in thread
From: Björn Persson @ 2004-05-09 12:38 UTC (permalink / raw)


Simon Wright wrote:

> The compiler should probably have said something to point you at:
> 
>    AARM 3.9.3(10), For an abstract type declared in a visible part, an
>    abstract primitive subprogram shall not be declared in the private
>    part, unless it is overriding an abstract subprogram implicitly
>    declared in the visible part. For a tagged type declared in a
>    visible part, a primitive function with a controlling result shall
>    not be declared in the private part, unless it is overriding a
>    function implicitly declared in the visible part.

I can't see how that would apply to this case. The only abstract type 
declared in a visible part is Intermediate_Definition, and the copmiler 
doesn't complain about that one. It complains about 
Typed_Parameter_Definition, which is concrete and declared in a private 
part.

> In an equivalent place in the Booch Components, I make the subprogram
> concrete and say
> 
>    function Item_At (C : Container; Index : Positive) return Item_Ptr is
>    begin
>       raise Should_Have_Been_Overridden;
>       return null;
>    end Item_At;

That workaround works for this small example, but when I applied it to 
the real library I ran into other problems instead, like "cannot find 
body of generic package "Common_Functions"". I give up. I'll have to 
live with virtually identical code in at least four places.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-08  6:15     ` Martin Krischik
@ 2004-05-09 12:42       ` Björn Persson
  0 siblings, 0 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-09 12:42 UTC (permalink / raw)


Martin Krischik wrote:

> It is not odd. When the keyword "tagged" is only inside the private section
> then the "tag is hidden". Only child packages can see the tag and can
> extend the class.

Apparently a private subpackage can extend the type too, and only 
subpackages and child packages are involved here. Simon's workaround 
with Should_Have_Been_Overridden worked for the example, so there is no 
problem with the type extension itself. It's just that abstract 
subprograms don't work.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-09 12:38       ` Björn Persson
@ 2004-05-10  5:43         ` Simon Wright
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Wright @ 2004-05-10  5:43 UTC (permalink / raw)


Bj�rn Persson <spam-away@nowhere.nil> writes:

> Simon Wright wrote:
> 
> > The compiler should probably have said something to point you at:
> >    AARM 3.9.3(10), For an abstract type declared in a visible part,
> > an
> >    abstract primitive subprogram shall not be declared in the private
> >    part, unless it is overriding an abstract subprogram implicitly
> >    declared in the visible part. For a tagged type declared in a
> >    visible part, a primitive function with a controlling result shall
> >    not be declared in the private part, unless it is overriding a
> >    function implicitly declared in the visible part.
> 
> I can't see how that would apply to this case. The only abstract type
> declared in a visible part is Intermediate_Definition, and the
> copmiler doesn't complain about that one. It complains about
> Typed_Parameter_Definition, which is concrete and declared in a
> private part.

Hmm, yes, sorry. Sounds a bit like a compiler problem, then. Either
it's seeing a problem when it shouldn't or it's giving you the wrong
diagnosis.

FYI GNAT 3.16a1 & 5.02a behave the same.

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: Why can't I override these functions?
  2004-05-07 10:43 Why can't I override these functions? Björn Persson
  2004-05-07 17:15 ` Jim Rogers
  2004-05-07 18:42 ` Georg Bauhaus
@ 2004-05-10 11:49 ` Martin Dowie
  2004-05-10 12:13   ` Björn Persson
  2004-05-13  7:23 ` Björn Persson
  3 siblings, 1 reply; 13+ messages in thread
From: Martin Dowie @ 2004-05-10 11:49 UTC (permalink / raw)


Bj�rn Persson <spam-away@nowhere.nil> wrote in message news:<HLJmc.58389$mU6.237165@newsb.telia.net>...
> I have a generic package with a tagged type Parameter Definition, a 
> generic subpackage with a type Intermediate Definition derived from 
> Parameter Definition, and a generic child package with a type 
> Typed Parameter Definition derived from Intermediate Definition. See the 
> code below. Gnat gives me an error on the declaration of 
> Typed Parameter Definition:
[snip]

For what it's worth ObjectAda (U13) compiles this quite happily.



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

* Re: Why can't I override these functions?
  2004-05-10 11:49 ` Martin Dowie
@ 2004-05-10 12:13   ` Björn Persson
  0 siblings, 0 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-10 12:13 UTC (permalink / raw)


Martin Dowie wrote:
> Björn Persson <spam-away@nowhere.nil> wrote in message news:<HLJmc.58389$mU6.237165@newsb.telia.net>...
> 
>>I have a generic package with a tagged type Parameter Definition, a 
>>generic subpackage with a type Intermediate Definition derived from 
>>Parameter Definition, and a generic child package with a type 
>>Typed Parameter Definition derived from Intermediate Definition. See the 
>>code below. Gnat gives me an error on the declaration of 
>>Typed Parameter Definition:
> 
> [snip]
> 
> For what it's worth ObjectAda (U13) compiles this quite happily.

And according to someone who sent me an email, Apex does the same. Looks 
like it's time for another visit to GCC's Bugzilla.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

* Re: Why can't I override these functions?
  2004-05-07 10:43 Why can't I override these functions? Björn Persson
                   ` (2 preceding siblings ...)
  2004-05-10 11:49 ` Martin Dowie
@ 2004-05-13  7:23 ` Björn Persson
  3 siblings, 0 replies; 13+ messages in thread
From: Björn Persson @ 2004-05-13  7:23 UTC (permalink / raw)


Reported in Bugzilla:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15408

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




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

end of thread, other threads:[~2004-05-13  7:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-07 10:43 Why can't I override these functions? Björn Persson
2004-05-07 17:15 ` Jim Rogers
2004-05-07 18:15   ` Björn Persson
2004-05-07 18:42 ` Georg Bauhaus
2004-05-07 19:38   ` Björn Persson
2004-05-08  6:15     ` Martin Krischik
2004-05-09 12:42       ` Björn Persson
2004-05-08 11:34     ` Simon Wright
2004-05-09 12:38       ` Björn Persson
2004-05-10  5:43         ` Simon Wright
2004-05-10 11:49 ` Martin Dowie
2004-05-10 12:13   ` Björn Persson
2004-05-13  7:23 ` Björn Persson

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