2

I'm trying to get a couple of tasks to be able to call each other, but I don't seem very good with this limited with thing..

I have a spec sctrain-trains.ads

limited with SCTrain.Stations;
with SCTrain.Travellers, SCTrain.Tracks, Ada.Strings.Unbounded;
use SCTrain.Travellers, SCTrain.Tracks, Ada.Strings.Unbounded;

package SCTrain.Trains is
   type my_station_access_t is access all Stations.Station;

   task type Train is
      entry Start(leaving: my_station_access_t; arriving: my_station_access_t);
   end Train;

end SCTrain.Trains;

and its .adb

with SCTrain.Stations;
use SCTrain.Stations;

package body SCTrain.Trains is

   task body Train is
      destination: my_station_access_t;
   begin
      accept Start(leaving: my_station_access_t; arriving: my_station_access_t) do
         destination := arriving;
      end Start;
      destination.Gogo(1);
   end Train;

end SCTrain.Trains;

I found in the documents I've been reading that withing the "circular" package in the body would allow smooth executions, but apparently I still have an invalid prefix in selected component "destination" because dereference must not be of an incomplete type (RM 3.10.1), and those errors stay there even without the with and use in the package body. I'm sure I'm missing something, possibly something very basic, and I'd really love to know what that is. The problem I'm trying to solve is that the Train needs a signal from the Station to be allowed to leave and still able to communicate its arrival time afterwards.

I'm using the latest GNAT-GPL.

Thank you very much.

edit: adding Station's code

limited with SCTrain.Trains;
with Ada.Calendar, Ada.Strings.Unbounded, Ada.Text_IO;
use Ada.Calendar, Ada.Strings.Unbounded, Ada.Text_IO;

package SCTrain.Stations is

   task type Station is
      entry Gogo(name_d : Integer := 0);
   end Station;

end SCTrain.Stations;

and the body:

with SCTrain.Trains;
use SCTrain.Trains;

package body SCTrain.Stations is
   task body Station is
      name  : Integer;
   begin
      accept Gogo (name_d : Integer := 0) do
         name := name_d;
         Put_Line("Station " & Integer'Image(name) & " is alive");
      end Gogo;
   end Station;

end SCTrain.Stations;
4

2 回答 2

2

仅在一个方向上使用limited with,在另一个方向上正常with使用。

于 2013-07-26T07:06:03.367 回答
0

替换destinationby的声明

destination: access Stations.Station;

或将违规行替换为

destination.all.Gogo(1);

我不知道这是编译器错误还是正确的行为;看起来很可疑!

后来:我在 comp.lang.ada 上发布了一个更精简的示例,其中一位常驻专家同意这是一个错误;我会向 AdaCore 报告。

于 2013-07-26T18:32:53.640 回答