Re: [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]> |
Merci Laurent, pour cette réponse.
Hum, j'avais bien lu (survolé plutôt) ce paragraphe, tiré de
l'excellent "Rationale for Ada 2005" de J. Barnes, excellent pour
aborder Ada 2005.
Je comprends en effet que la dérivation (extension) d'un type objet
au sein d'un sous-programme peut mener à un PROGRAM_ERROR.
En fait, il n'y a pas d'interdiction d'Ada 2005 de créer et de
dériver des types objets au sein d'un sous-programme, exemple du
manuel sans erreur :
procedure basic_obj is
type Point is tagged
record
X, Y : Float := 0.0;
end record;
type Expression is tagged null record;
-- Components will be added by each extension
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Painted_Point is new Point with
record
Paint : Color := White;
end record;
-- Components X and Y are inherited
Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
begin
null;
end basic_obj;
D'ailleurs, GNAT autorise même la déclaration mais pas l'utilisation:
procedure basic_obj2 is
type Point is tagged
record
X, Y : Float := 0.0;
end record;
procedure Init (O: in out Point; X, Y : Float) is
begin
O := (X, Y);
end;
procedure Deplace (O: in out Point'Class; DX, DY : Float) is
begin
O.X := O.X + DX;
O.Y := O.Y + DY;
end;
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Painted_Point is new Point with
record
Paint : Color := White;
end record;
-- Components X and Y are inherited
procedure Init (O: in out Painted_Point; X, Y : Float; P: Color) is
begin
Init (O, X, Y); -- error
O.Paint := P;
end;
Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
OP : Painted_Point := Origin;
begin
OP.Deplace (3.0, 4.0);
end basic_obj2;
Erreur avec GNAT:
$ gnatmake -gnatf -g basic_obj2
gcc -c -gnatf -g basic_obj2.adb
basic_obj2.adb:44:03: no candidate interpretations match the actuals:
basic_obj2.adb:44:03: missing argument for parameter "P" in call to
"init" declared at line 42
basic_obj2.adb:44:09: expected type "Point" defined at line 18
basic_obj2.adb:44:09: found type "Painted_Point" defined at line 36
basic_obj2.adb:44:09: ==> in call to "Init" at line 23
gnatmake: "basic_obj2.adb" compilation error
N'est ce pas trop restrictif d'interdire, au sein d'un sous-
programme, l'utilisation de primitives d'un type objet non dérivé ou
dérivant d'un type déclaré au même niveau ?
Cordialement, Pascal.
http://blady.perso.orange.fr
Le 6 août 07 à 13:30, Laurent GUERBY a écrit :
> On Sun, 2007-08-05 at 19:25 +0200, Pascal wrote:
>
>> 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 ?
>
> Le probleme c'est la declaration des types, pas l'emploi.
> Ada 2005 par rapport en 1995 permets d'etendre
> les types dans des procedures, un exemple :
>
> http://www.adaic.org/standards/05rat/html/Rat-2-5.html
>
> Laurent
>
>
_______________________________________________
Site WWW de l'association Ada-France: http://www.ada-france.org/
[email protected]
http://www.ada-france.org/mailman/listinfo/ada-france