comp.lang.ada
 help / color / mirror / Atom feed
* generic and visibility
@ 2004-11-04 15:23 mferracini
  2004-11-04 18:59 ` Georg Bauhaus
  2004-11-05  3:39 ` John Woodruff
  0 siblings, 2 replies; 6+ messages in thread
From: mferracini @ 2004-11-04 15:23 UTC (permalink / raw)


i'm new on ADA, and i hav some problem
with generic.

this is an exemple



------------------------------------
package Manage is
generic
Id : integer;
with procedure Init;
with procedure Job;
package Det is

procedure Start(
Status :    out Integer );
end Det;
end Manage;

----------------------------------------

with Ada.Text_Io;
with Ada.Task_Identification;

package body Applicazione is
I : Integer := 0;

procedure Init is
begin
I:=1;
end Init;

procedure Job is
begin
Ada.Text_Io.Put(Item => "> mi sbatto!  ");
I:=I+1;
Ada.Text_Io.Put(Item => Integer'Image (I));
Ada.Text_Io.New_Line;
end Job;

end Applicazione;
-----------------------------------------

with Manage;
with Applicazione;


package Fake_App is new Manage_Task.Det_Task_M_Pack
(
Id_task => 1,
Init_Job => Applicazione.Init,
Job => Applicazione.Job);

---------------


with Fake_App;

procedure Test is
begin
Fake_app.job;
end Test;

---------------------------------------------------------------------------------
job in not a visible entry of fake_app

how i can do?
thanks




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

* Re: generic and visibility
  2004-11-04 15:23 generic and visibility mferracini
@ 2004-11-04 18:59 ` Georg Bauhaus
  2004-11-05  3:39 ` John Woodruff
  1 sibling, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2004-11-04 18:59 UTC (permalink / raw)


mferracini <maurizio.ferracini@gmail.com> wrote:
 
 [...]
 
: package Fake_App is new Manage_Task.Det_Task_M_Pack
: (
: Id_task => 1,
: Init_Job => Applicazione.Init,
: Job => Applicazione.Job);

 [...]
 

: job in not a visible entry of fake_app
: 
: how i can do?

The sources are a bit incomplete, so I tried guessing (why is
there `Id_task' when the formal parameter is really `Id', etc.?)
`Job' is the name of a formal parameter of `Manage.Det' (where does
`_Task_M_Pack' come from?)  The subprograms that can be visible from
the outside of an instance of Manage.Det are those in the package Det,
that is, `Start'. It seems you want to use `Applicazione.Job'
as a generic parameter, instantiatin Manage.Det. This will get you
an instance, Fake_App, that has one visible subprogram, `Start'.
The `Job' subprogram is (and remains) visible via `Applicazione'.


-- Georg



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

* Re: generic and visibility
  2004-11-04 15:23 generic and visibility mferracini
  2004-11-04 18:59 ` Georg Bauhaus
@ 2004-11-05  3:39 ` John Woodruff
  1 sibling, 0 replies; 6+ messages in thread
From: John Woodruff @ 2004-11-05  3:39 UTC (permalink / raw)


"mferracini" <maurizio.ferracini@gmail.com> wrote in message news:<1099581795.057353.199160@c13g2000cwb.googlegroups.com>...
> i'm new on ADA, and i hav some problem
> with generic.
> 
> this is an exemple
> 
> 
> 
> ------------------------------------
> package Manage is
> generic
> Id : integer;
> with procedure Init;
> with procedure Job;
> package Det is
> 
> procedure Start(
> Status :    out Integer );
> end Det;
> end Manage;
> 
> ----------------------------------------
> 
> with Ada.Text_Io;
> with Ada.Task_Identification;
> 
> package body Applicazione is
> I : Integer := 0;
> 
> procedure Init is
> begin
> I:=1;
> end Init;
> 
> procedure Job is
> begin
> Ada.Text_Io.Put(Item => "> mi sbatto!  ");
> I:=I+1;
> Ada.Text_Io.Put(Item => Integer'Image (I));
> Ada.Text_Io.New_Line;
> end Job;
> 
> end Applicazione;
> -----------------------------------------
> 
> with Manage;
> with Applicazione;
> 
> 
> package Fake_App is new Manage_Task.Det_Task_M_Pack
> (
> Id_task => 1,
> Init_Job => Applicazione.Init,
> Job => Applicazione.Job);
> 
> ---------------
> 
> 
> with Fake_App;
> 
> procedure Test is
> begin
> Fake_app.job;
> end Test;
> 
> ---------------------------------------------------------------------------------
> job in not a visible entry of fake_app
> 
> how i can do?
> thanks

I'm guessing "homework" here, so I'll give (I hope) constructive
hints, but not solve the problem completely ----

You have omitted a couple items that are needed before I can answer
your direct question.

You need to give a specification for the package Applicazione.  You
gave only a body, and every package needs a spec (most need a body as
well). 

It probably looks like this:

package Applicazione is
  procedure Init ;
  procedure Job ;
end Applicazione;
-----

Next, your package that you call "Fake_App" is not correct.  Manage
contains an internal package called Det.  So you need to "instantiate"
that internal package by naming it properly when you say something
like

  package Fake_App is new <<correct name here>> with its parameters.
-----

Then finally, why are you unable to find an entry "job" in the
instance called Fake_App?

When you make a new instance (the thing you're calling Fake_App),
it has the  subprograms that were visible in its spec.  Start is the
ONLY visible subprogram declared.  Consider the difference between the
generic formal procedure "Job" and the procedure Start.   

HTH
John



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

* Generic and visibility...
@ 2005-06-10 21:34 e.coli
  2005-06-11  1:18 ` Larry Hazel
  2005-06-11  4:44 ` Preben Randhol
  0 siblings, 2 replies; 6+ messages in thread
From: e.coli @ 2005-06-10 21:34 UTC (permalink / raw)


my program is structured like this:

--bar.ads
package Bar is
   generic
      with procedure Quuz;
   package Baz is

      task type Dummy is
         entry Run;
      end Dummy;

      type Ptr_Dummy is access Dummy;

      procedure Quz (
            X :    out Ptr_Dummy );

   end Baz;
 end Bar;

--bar.adb
with Ada.Text_Io;

package body Bar is
    T_Array : array (Integer range 1 .. 10) of Baz.Ptr_Dummy; --error
   package body Baz is

      task body Dummy is
      begin
         accept Run do
            Ada.Text_Io.Put_Line
               (Item => "Hello, Word!");
            Quuz; --generic procedure
         end Run;
      end Dummy;

      procedure Quz (
            X :    out Ptr_Dummy ) is
      begin
         X := new Dummy;
      end Quz;

   end Baz;
end Bar;


why i can't acces to Baz.Ptr_Dummy?
my deal is see the task pointer X outside Baz package.

thanks




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

* Re: Generic and visibility...
  2005-06-10 21:34 Generic " e.coli
@ 2005-06-11  1:18 ` Larry Hazel
  2005-06-11  4:44 ` Preben Randhol
  1 sibling, 0 replies; 6+ messages in thread
From: Larry Hazel @ 2005-06-11  1:18 UTC (permalink / raw)


e.coli wrote:
> my program is structured like this:
> 
> --bar.ads
> package Bar is
>    generic
>       with procedure Quuz;
>    package Baz is
> 
>       task type Dummy is
>          entry Run;
>       end Dummy;
> 
>       type Ptr_Dummy is access Dummy;
> 
>       procedure Quz (
>             X :    out Ptr_Dummy );
> 
>    end Baz;
>  end Bar;
> 
> --bar.adb
> with Ada.Text_Io;
> 
> package body Bar is
>     T_Array : array (Integer range 1 .. 10) of Baz.Ptr_Dummy; --error
>    package body Baz is
> 
>       task body Dummy is
>       begin
>          accept Run do
>             Ada.Text_Io.Put_Line
>                (Item => "Hello, Word!");
>             Quuz; --generic procedure
>          end Run;
>       end Dummy;
> 
>       procedure Quz (
>             X :    out Ptr_Dummy ) is
>       begin
>          X := new Dummy;
>       end Quz;
> 
>    end Baz;
> end Bar;
> 
> 
> why i can't acces to Baz.Ptr_Dummy?
> my deal is see the task pointer X outside Baz package.
> 
> thanks
> 
There is no package Baz, thus no Baz.Ptr_Dummy.  You must instanciate 
the generic package and reference the Ptr_Dummy in that package.



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

* Re: Generic and visibility...
  2005-06-10 21:34 Generic " e.coli
  2005-06-11  1:18 ` Larry Hazel
@ 2005-06-11  4:44 ` Preben Randhol
  1 sibling, 0 replies; 6+ messages in thread
From: Preben Randhol @ 2005-06-11  4:44 UTC (permalink / raw)
  To: comp.lang.ada

On Fri, Jun 10, 2005 at 02:34:12PM -0700, e.coli wrote:
> 
> why i can't acces to Baz.Ptr_Dummy?
> my deal is see the task pointer X outside Baz package.

Before you can use this package, you have to instantiate it.

   http://www.it.bton.ac.uk/staff/je/adacraft/ch12.htm

Preben



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

end of thread, other threads:[~2005-06-11  4:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-04 15:23 generic and visibility mferracini
2004-11-04 18:59 ` Georg Bauhaus
2004-11-05  3:39 ` John Woodruff
  -- strict thread matches above, loose matches on Subject: below --
2005-06-10 21:34 Generic " e.coli
2005-06-11  1:18 ` Larry Hazel
2005-06-11  4:44 ` Preben Randhol

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