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

Pascal <[email protected]>
Newsgroups gmane.comp.lang.ada.france
Message-ID <[email protected]>
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

_______________________________________________
Site WWW de l'association Ada-France: http://www.ada-france.org/
[email protected]
http://www.ada-france.org/mailman/listinfo/ada-france
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.