comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Runtime type selection
Date: Mon, 12 Oct 2009 18:42:56 -0500
Date: 2009-10-12T18:42:56-05:00	[thread overview]
Message-ID: <hb0f14$2gt$1@munin.nbi.dk> (raw)
In-Reply-To: 4ad23819$0$6256$4f793bc4@news.tdc.fi

"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message 
news:4ad23819$0$6256$4f793bc4@news.tdc.fi...
...
> Did you read about the package Ada.Tags (RM 3.9)? There is a generic 
> function Ada.Tags.Generic_Dispatching_Constructor that takes a tag as 
> parameter and creates an object with that tag, but I don't hink there is 
> any way to find the tags for all types in a given derivation class. So 
> even with  Ada.Tags.Generic_Dispatching_Constructor your program still has 
> to register the types, or their tags, or a prototype object of each type, 
> to create the program-accessible set of types/tags that can be in the 
> graph.
>
> Perhaps some expert can explain why this reflection capability (find tags 
> for all derived types in a class) was not included in Ada.Tags? Perhaps 
> because Ada run-time systems do not need such a function for their own 
> purposes?

I think that would be impossible in general, for the same reason that the 
rules about what tags are returned from calls to Internal_Tag are mostly 
written with "may". The problem is that tagged types can be created and 
cease to exist asychronously with respect to a call to a function in 
Ada.Tags. (For instance, if another task creates a tagged type by calling a 
subprogram with such a type declaration.) The model of Ada.Tags is that is 
can be implemented either with a mostly static data structure (created at 
link-time) or with a fully dynamic structure. In the latter case, complex 
locking would be required to ensure any particular (useful) answer for one 
of these functions. In the former case, something similar to the dynamic 
structure (and locking) would be required to avoid returning non-existent 
tags. It was felt that such requirements would add a lot of complication and 
runtime cost to the implementation of this package without a corresponding 
benefit.

Finally, to actually implement some way to determine all of the tags of a 
particular class would require either a brute force search of all tags (very 
slow) or some complex additional data structures. (Remember that *every* 
tagged type and subtype has a corresponding 'Class, so this structure could 
get very large if you are using software that defines a lot of tagged types 
as Claw does.) The only language requirement is that each tagged type is 
connected to its immediate parent (in order to check type conversions), 
anything else further would be needed only to implement your proposed 
function. Even a list of all tags is not required to implement the language 
(although you may have a way to get it depending on your Ada.Tags 
implementation).

                                                 Randy.





  parent reply	other threads:[~2009-10-12 23:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-11 16:41 Runtime type selection xorque
2009-10-11 17:02 ` Niklas Holsti
2009-10-11 17:15   ` xorque
2009-10-11 19:54     ` Niklas Holsti
2009-10-12  9:26       ` Georg Bauhaus
2009-10-12 12:02         ` xorque
2009-10-12 23:42       ` Randy Brukardt [this message]
2009-10-13  6:50         ` Niklas Holsti
2009-10-13  0:59       ` Adam Beneschan
2009-10-13  7:01         ` Niklas Holsti
2009-10-11 17:15 ` mockturtle
2009-10-11 20:06 ` Dmitry A. Kazakov
2009-10-13 10:45   ` Colin Paul Gloster
2009-10-13 10:17     ` Dmitry A. Kazakov
2009-10-13 15:11 ` xorque
2009-10-13 15:50   ` Dmitry A. Kazakov
2009-10-13 16:02     ` xorque
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox