Re: Overriding et primitives.

Jean-Pierre Rosen <[email protected]>
Newsgroups gmane.comp.lang.ada.france
Message-ID <[email protected]>
Pascal a écrit :
> 1) Ada 2005 a ajouté le mot clé "overriding", voir RM Ada 2005 :
> "8.3.1 Overriding Indicators
> 1/2
> An overriding_indicator is used to declare that an operation is  
> intended to override (or not override) an inherited operation.
> Syntax
> 2/2
> overriding_indicator ::= [not] overriding"
> 
> Sans ajouter de mot clé supplémentaire, cette fonctionnalité aurait  
> pu s'obtenir avec un ou deux pragma comme:
> pragma Overriding (Identifier);
> pragma Not_Overriding (Identifier);
> 
Cela avait été proposé, mais rejeté car les pragmas ne doivent pas être 
utilisés d'une façon qui modifie la légalité d'un programme. Bon, il y a 
des exceptions (pragma import), mais on a préféré respecter le principe 
général.

> 2) Ada 2005 permet de ne plus exiger de redefinition d'une fonction  
> retournant le type objet, voir "Rationale for  Ada 2005" :
> "The reader may recall the general rule in Ada 95 that a function  
> that is a primitive operation of a
> tagged type and returns a value of the type, must always be  
> overridden when the type is extended.
> Ada 2005 sensibly allows the functions to be inherited provided
> that the extension is visibly null (and that there is no new  
> discriminant part) and so no overriding is
> required."
> Cependant dans le cas d'une extension non nulle du type objet,  
> certaines situations font que la redéfinition de la fonction telle  
> quelle (avec les mêmes paramètres) est inutile pour l'utilisateur  
> mais que sa surcharge avec d'autres paramètres est utile.
> Ne serait-il pas intéressant dans ce cas d'utiliser un pragma comme :
> pragma Not_A_Primitive (Identifier);
> 
Il suffit de déclarer la fonction dans un sous-paquetage pour l'empecher 
d'être primitive. J'ai le cas dans AdaControl, où j'ai un constructeur 
pour le type Basic_Context. Le constructeur s'appelle New_Context dans 
le sous-paquetage Basic. Comme ça j'écris Basic.New_Context, alors que 
si je n'avais pas fait de sous-paquetage, j'aurais surement appelé la 
fonction Basic_New_Context. Bref, on ne peut pas dire que le niveau de 
paquetage supplémentaire soit vraiment génant...

-- 
---------------------------------------------------------
            J-P. Rosen ([email protected])
Visit Adalog's web site at http://www.adalog.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.