comp.lang.ada
 help / color / mirror / Atom feed
* [Q]: Generic subprogram instantiation
@ 1996-07-05  0:00 Michael Bartz
  1996-07-06  0:00 ` Robert Dewar
  1996-07-06  0:00 ` Robert A Duff
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Bartz @ 1996-07-05  0:00 UTC (permalink / raw)




I am trying to create an instantiated subprogram within a declarative
block of a main subprogram.  I want to pick the particular instantiation
at run-time so I put the declarative block within one of the choices
within a case statement.  I am instatiating the subprograms so that each
particular subprogram can pick up some instantiated packages unique to
each particular choice (of the case statement).

The problem is that GNAT flags this arrangement with the following:

main.adb:26:09: "sub_main" is hidden within declaration of instance
main.adb:33:09: "sub_main" is hidden within declaration of instance

On surface inspection, I am not sure I understand exactly why the compiler
has flagged this? 

Can anyone explain this error message for me in the context of the program
fragments below?

I will send full sources if required.




--main.adb
with all_field_types; use all_field_types;
with sub_main;
with field;
with text_io; use text_io;

procedure main is

  N : Positive := 8;

  package int_io is new integer_io(Integer);

begin

  case N is
    when 8 =>
      declare
        package galois is new Field(GF8_types);
        procedure sub_main is new sub_main(galois);
      begin
        sub_main(N);
      end;
    when 16 =>
      declare
        package galois is new Field(GF16_types);
        procedure sub_main is new sub_main(galois);
      begin
        sub_main(N);
      end;
    when others =>
      null;

  end case;

end main;

--sub_main.adb
procedure sub_main(Z:Integer) is
  use local_field;
  X : Field_Element := 1;
  A : Boolean;

begin

  A := Value(0);

end sub_main;

--sub_main.ads
with field;
generic
  with package local_field is new field (<>);
  procedure sub_main(Z:Integer);

-- 
Michael Bartz                            Proud Member of Team Ada(95)
The University of Memphis

m-bartz@memphis.edu




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

* Re: [Q]: Generic subprogram instantiation
  1996-07-05  0:00 [Q]: Generic subprogram instantiation Michael Bartz
  1996-07-06  0:00 ` Robert Dewar
@ 1996-07-06  0:00 ` Robert A Duff
  1996-07-11  0:00   ` Tucker Taft
  1 sibling, 1 reply; 5+ messages in thread
From: Robert A Duff @ 1996-07-06  0:00 UTC (permalink / raw)



In article <m-bartz-0507961333140001@macgalois.ee.memst.edu>,
Michael Bartz <m-bartz@memphis.edu> wrote:
>        procedure sub_main is new sub_main(galois);
                   ^^^^^^^^ 1      ^^^^^^^^ 2

The sub_main at 1 hides the outer sub_main, which you then illegally try
to reference at 2.  Call the procedure something different from the
generic.  (Note that generic procedures are NOT overloadable, unlike
procedures.)

- Bob





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

* Re: [Q]: Generic subprogram instantiation
  1996-07-05  0:00 [Q]: Generic subprogram instantiation Michael Bartz
@ 1996-07-06  0:00 ` Robert Dewar
  1996-07-06  0:00 ` Robert A Duff
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-07-06  0:00 UTC (permalink / raw)



Michael wrote

"        procedure sub_main is new sub_main(galois);"

GNAT is right to flag that, it is clearly illegal, since sub_main on the
right would refer to sub_main on the left if it was allowed to (which
it is not), and not to the outside sub_main. In fact the rule is that
sub_main is introduced by the declaration, but cannot be refrerenced
until the declaration is complete.

To rewrite this correctly, use appropriate qualiffication for the
sub_main reference on the right hand side to get the one you want!





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

* Re: [Q]: Generic subprogram instantiation
  1996-07-11  0:00   ` Tucker Taft
@ 1996-07-11  0:00     ` Robert A Duff
  0 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 1996-07-11  0:00 UTC (permalink / raw)



In article <DuDzvD.JwK.0.-s@inmet.camb.inmet.com>,
Tucker Taft <stt@henning.camb.inmet.com> wrote:
>: >        procedure sub_main is new sub_main(galois);

>So I believe this line should be accepted.

Oops -- you're right, of course.

It was illegal in Ada 83, by RM83-8.3(16).  Interestingly, this was
changed primarily to make the compiler's job a little bit easier.

- Bob




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

* Re: [Q]: Generic subprogram instantiation
  1996-07-06  0:00 ` Robert A Duff
@ 1996-07-11  0:00   ` Tucker Taft
  1996-07-11  0:00     ` Robert A Duff
  0 siblings, 1 reply; 5+ messages in thread
From: Tucker Taft @ 1996-07-11  0:00 UTC (permalink / raw)



Robert A Duff (bobduff@world.std.com) wrote:
: In article <m-bartz-0507961333140001@macgalois.ee.memst.edu>,
: Michael Bartz <m-bartz@memphis.edu> wrote:
: >        procedure sub_main is new sub_main(galois);
:                    ^^^^^^^^ 1      ^^^^^^^^ 2

: The sub_main at 1 hides the outer sub_main, which you then illegally try
: to reference at 2.  Call the procedure something different from the
: generic.  (Note that generic procedures are NOT overloadable, unlike
: procedures.)

I hate to disagree with both Bob and Robert, but the procedure named
"sub_main" is not introduced until *after* the generic instantiation
in Ada 95.  See RM95 8.2(2):

   ... except in the case of an overloadable declaration [like the above],
   in which case the immediate scope starts just after the place where the
   profile of the callable entity is determined (which is at the end of the
   _specification for the callable entity, or at the end of the 
   generic_instantiation if an instance).

So I believe this line should be accepted.

: - Bob

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-05  0:00 [Q]: Generic subprogram instantiation Michael Bartz
1996-07-06  0:00 ` Robert Dewar
1996-07-06  0:00 ` Robert A Duff
1996-07-11  0:00   ` Tucker Taft
1996-07-11  0:00     ` Robert A Duff

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