[ada-france] [GNAT GPL 2007] Compilation d'un example objet du manuel Ada 2005.

Pascal sur.pignard at wanadoo.fr
Dim 5 Aou 19:25:14 CEST 2007


Bonjour.

L'exemple est pris au chapitre : 3.9.4 Interface Types

procedure basic_int is
type Gender is (M, F);
type Person(<>);    -- incomplete type declaration
type Car is tagged; -- incomplete type declaration
type Person_Name is access Person;
type Car_Name    is access all Car'Class;
type Car is tagged
    record
       Number  : Integer;
       Owner   : Person_Name;
    end record;
type Person(Sex : Gender) is
    record
       Name     : String(1 .. 20);
       --Birth    : Date;
       Age      : Integer range 0 .. 130;
       Vehicle  : Car_Name;
       case Sex is
          when M => Wife           : Person_Name(Sex => F);
          when F => Husband        : Person_Name(Sex => M);
       end case;
    end record;

type Queue is limited interface;
procedure Append(Q : in out Queue; Person : in Person_Name) is  
abstract; -- warning
procedure Remove_First(Q      : in out Queue;							-- warning
                        Person : out Person_Name) is abstract;
function Cur_Count(Q : in Queue) return Natural is abstract;				--  
warning
function Max_Count(Q : in Queue) return Natural is abstract;				--  
warning
Queue_Error : exception;
-- Append raises Queue_Error if Count(Q) = Max_Count(Q)
-- Remove_First raises Queue_Error if Count(Q) = 0
procedure Transfer(From   : in out Queue'Class;
                    To     : in out Queue'Class;
                    Number : in     Natural := 1) is
    Person : Person_Name;
begin
    for I in 1..Number loop
       Remove_First(From, Person);
       Append(To, Person);
    end loop;
end Transfer;

type Fast_Food_Queue is new Queue with record
             Menu : natural;
			end record;
procedure Append(Q : in out Fast_Food_Queue; Person : in Person_Name) is
   begin
   Q.Menu := Q.Menu + 1;
   end;
procedure Remove_First(Q : in out Fast_Food_Queue; Person : in  
Person_Name) is
   begin
   Q.Menu := Q.Menu - 1;
   end;
function Cur_Count(Q : in Fast_Food_Queue) return Natural is
   begin
   return Q.Menu;
   end;
function Max_Count(Q : in Fast_Food_Queue) return Natural is
   begin
   return Q.Menu'Last;
   end;

Cashier, Counter : Fast_Food_Queue;
George : Person_Name := new Person(M);

begin
-- Add George (see 3.10.1) to the cashier's queue:
Append (Cashier, George);
-- After payment, move George to the sandwich counter queue:
Transfer (Cashier, Counter);
end basic_int;

La compilation avec GNAT GPL 2007 présente des avertissements (plutôt  
des erreurs) d'utilisation de primitives objets dans une procédure :

$ gnatmake -g -gnatf basic_int.adb
gcc -c -g -gnatf basic_int.adb
basic_int.adb:44:11: warning: not dispatching (must be defined in a  
package spec)
basic_int.adb:45:11: warning: not dispatching (must be defined in a  
package spec)
basic_int.adb:47:10: warning: not dispatching (must be defined in a  
package spec)
basic_int.adb:48:10: warning: not dispatching (must be defined in a  
package spec)
basic_int.adb:59:07: cannot call abstract subprogram "Remove_First"
basic_int.adb:59:20: class-wide argument not allowed here
basic_int.adb:59:20: "Remove_First" is not a dispatching operation of  
"Queue"
basic_int.adb:60:07: cannot call abstract subprogram "Append"
basic_int.adb:60:14: class-wide argument not allowed here
basic_int.adb:60:14: "Append" is not a dispatching operation of "Queue"
basic_int.adb:81:10: prefix of "last" attribute must be a type
gnatmake: "basic_int.adb" compilation error

Existe-t-il une règle Ada 2005 empêchant l'emploi des primitives  
objets dans une procédure ?
Est-ce une restriction de GNAT ?

Merci pour vos réponses, Pascal.
http://blady.perso.orange.fr


-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: http://www.ada-france.org/pipermail/ada-france/attachments/20070805/2e0042e7/attachment.htm 


Plus d'informations sur la liste de diffusion Ada-France