comp.lang.ada
 help / color / mirror / Atom feed
* Controlled types in local generics?
@ 1999-12-30  0:00 Ted Dennison
  1999-12-30  0:00 ` Mats Weber
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Ted Dennison @ 1999-12-30  0:00 UTC (permalink / raw)


I have a simple controlled type declared in a generic package. I tried
to instantiate it inside of a declare block. When I compile that source
file with gnat I get the following error message:

     token_list_test.adb:59:07: instantiation error at
     opentoken-token-list.ads:96
     token_list_test.adb:59:07: controlled type must be declared at
     the library level

Surely this isn't saying that all controlled types must be declared at
the library level? I can't find anything in the LRM that says that, and
I'm pretty sure some of the booch components use generics with
controlled types in them.

This is one instance where I'd dearly love to have an LRM reference in
the error message...

--
T.E.D.

Home - mailto:dennison@telepath.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 Controlled types in local generics? Ted Dennison
                   ` (2 preceding siblings ...)
  1999-12-30  0:00 ` Florian Weimer
@ 1999-12-30  0:00 ` Robert Dewar
  1999-12-30  0:00   ` Gautier
  1999-12-30  0:00 ` Simon Wright
  4 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1999-12-30  0:00 UTC (permalink / raw)


In article <386AFDA8.7C3110CC@telepath.com>,
  Ted Dennison <dennison@telepath.com> wrote:

>      token_list_test.adb:59:07: controlled type must be
>                                 declared at the library level
>
> Surely this isn't saying that all controlled types must be
> declared at the library level?

That's pretty amusing really. The error message says quite
clearly X, and you respond by saying "surely the error
message is not saying X" :-)

Yes, indeed the error message means what it says. The only
problem here is your incredulity :-)

> This is one instance where I'd dearly love to have an LRM
> reference in the error message...

Well perhaps, but really it would serve no purpose except to
confirm that the error message is correct. Perhaps you would
be more willing to believe it if you read it in the RM than
when GNAT tells you clearly :-)

There are various ways to work around this, it is one of the
areas where we have helped several of our supported customers.



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 Controlled types in local generics? Ted Dennison
  1999-12-30  0:00 ` Mats Weber
@ 1999-12-30  0:00 ` Robert Dewar
  1999-12-30  0:00   ` Ted Dennison
  1999-12-30  0:00 ` Florian Weimer
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1999-12-30  0:00 UTC (permalink / raw)


In article <386AFDA8.7C3110CC@telepath.com>,
  Ted Dennison <dennison@telepath.com> wrote:

>      token_list_test.adb:59:07: controlled type must be
>                                 declared at the library level
>
> Surely this isn't saying that all controlled types must be
> declared at the library level?

That's pretty amusing really. The error message says quite
clearly X, and you respond by saying "surely the error
message is not saying X" :-)

Yes, indeed the error message means what it says. The only
problem here is your incredulity :-)

> This is one instance where I'd dearly love to have an LRM
> reference in the error message...

Well perhaps, but really it would serve no purpose except to
confirm that the error message is correct. Perhaps you would
be more willing to believe it if you read it in the RM than
when GNAT tells you clearly :-)

There are various ways to work around this, it is one of the
areas where we have helped several of our supported customers.

Robert Dewar
Ada Core Technologies



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 ` Mats Weber
  1999-12-30  0:00   ` Ted Dennison
@ 1999-12-30  0:00   ` Robert Dewar
  1 sibling, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1999-12-30  0:00 UTC (permalink / raw)


In article <386B3015.F2F094CB@mail.com>,
  Mats Weber <matsw@mail.com> wrote:
> Maybe this could be circumvented by a generic package similar
> to Ada.Finalization that could be instantiated locally and
> provide the same facilities as Ada.Finalization ?
>
> Would it be feasible to write such a package for GNAT ?

Probably, but it is usually quite easy to work around this
problem in practical cases.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 Controlled types in local generics? Ted Dennison
                   ` (3 preceding siblings ...)
  1999-12-30  0:00 ` Robert Dewar
@ 1999-12-30  0:00 ` Simon Wright
  4 siblings, 0 replies; 13+ messages in thread
From: Simon Wright @ 1999-12-30  0:00 UTC (permalink / raw)


Ted Dennison <dennison@telepath.com> writes:

> Surely this isn't saying that all controlled types must be declared at
> the library level? I can't find anything in the LRM that says that, and
> I'm pretty sure some of the booch components use generics with
> controlled types in them.

The BCs are all generics, and they do use controlled types; and you
have to instantiate them at library level ..




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 ` Robert Dewar
@ 1999-12-30  0:00   ` Gautier
  1999-12-30  0:00     ` Ted Dennison
  0 siblings, 1 reply; 13+ messages in thread
From: Gautier @ 1999-12-30  0:00 UTC (permalink / raw)


> Well perhaps, but really it would serve no purpose except to
> confirm that the error message is correct. Perhaps you would
> be more willing to believe it if you read it in the RM than
> when GNAT tells you clearly :-)

People need strong religious references.

A message like:
  `This thing should be in that place'

sound less serious than words full of wisdom like
  `Ada RM 3.18, verse 5 (2), alinea 3: the construct
   named such_name (7.15) is allowed in the bla bla bla
   part of the so_and_so declaration, only if the
   previously named bla bla bla part is placed in an upper
   level compared to the level of the structure
   that encloses the imbricated substructure, under
   the condition that, firstly, bla bla bla... ... ...'

A bright demonstration is made in the `Life of Brian'
(the scene with the prophets)...

-- 
Gautier

_____\\________________\_______\_________
http://members.xoom.com/gdemont/gsoft.htm




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 ` Mats Weber
@ 1999-12-30  0:00   ` Ted Dennison
  1999-12-30  0:00   ` Robert Dewar
  1 sibling, 0 replies; 13+ messages in thread
From: Ted Dennison @ 1999-12-30  0:00 UTC (permalink / raw)


Mats Weber wrote:

> Yes, all controlled types must be library level. This is very
> unfortunate in my opinion.
>

Holy fatal flaws, Batman!

> The rule is not that all controlled types must be library level, but
> that a derived tagged type cannot be nested deeper than its parent.
> Ada.Finalization.Controlled is at library level, which implies that all
> controlled types also must be.

Ahh that makes more sense. But it still seems like a bad thing. I there a
reason why this restriction is a good thing for controlled types, or is it
purely an artifact of they way they are defined?

> Maybe this could be circumvented by a generic package similar to
> Ada.Finalization that could be instantiated locally and provide the same
> facilities as Ada.Finalization ?

That sound like the way Ada.Finalization should have been defined in the
first place. I hope something like that makes its way into the next language
revision.

> Would it be feasible to write such a package for GNAT ?

Perhaps. But I'm doing this for OpenToken, which needs to be
compiler-portable.

--
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00   ` Gautier
@ 1999-12-30  0:00     ` Ted Dennison
  0 siblings, 0 replies; 13+ messages in thread
From: Ted Dennison @ 1999-12-30  0:00 UTC (permalink / raw)


Gautier wrote:

> > Well perhaps, but really it would serve no purpose except to
> > confirm that the error message is correct. Perhaps you would
> > be more willing to believe it if you read it in the RM than
> > when GNAT tells you clearly :-)
>
> People need strong religious references.

Well, in my case I was just hoping for some kind of context to help me
understand the restriction. That way I might be able to see some kind of
work-around, or at least better understand a seemingly arbitrary
limitation.

But you should know that it is not polite to mock other people's
religous beliefs. Particularly not a religion as noble and beautiful as
LRMism.

...heretic.

:-)

--
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 ` Robert Dewar
@ 1999-12-30  0:00   ` Ted Dennison
  1999-12-31  0:00     ` Robert Dewar
  0 siblings, 1 reply; 13+ messages in thread
From: Ted Dennison @ 1999-12-30  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> There are various ways to work around this, it is one of the
> areas where we have helped several of our supported customers.

Hmm. Well, as I'm doing this work for free on OpenToken on my home
computer on my vaction for release as open sourced software to the
community, I don't suppose there's anyone else here who'd care to
provide this information to me gratis? I'm not too sure how expensive
ACT support is, but I seriously doubt it would fall in my household
budget. Particularly not after we call in the plummer to fix our toilet
leak...

As near as I can tell, there's no way around it. The whole point of the
object I'm trying to create is to manage items whose type is declared in
another generic. I can't take that type out of the generic, as it needs
a field that is of a user-defined enumeration (or other discrete) type.
I don't want to force that generic to be library-level, because in some
cases that causes other accessability level problems, and anyway there
is already a lot of code out there using OpenToken that instatiates it
within subroutines. I don't see any way to fake it out with pointers, as
these generic objects have to be dynamicly-allocated.

Its not a huge deal. I'll just use a fixed-size array approach, or
require users to call some kind of cleanup routine when they are done.
But the former is probably going to be slower, and the latter is going
to be less convienent for the users.

--
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 Controlled types in local generics? Ted Dennison
@ 1999-12-30  0:00 ` Mats Weber
  1999-12-30  0:00   ` Ted Dennison
  1999-12-30  0:00   ` Robert Dewar
  1999-12-30  0:00 ` Robert Dewar
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Mats Weber @ 1999-12-30  0:00 UTC (permalink / raw)


Ted Dennison wrote:

> Surely this isn't saying that all controlled types must be declared at
> the library level? I can't find anything in the LRM that says that, and
> I'm pretty sure some of the booch components use generics with
> controlled types in them.

Yes, all controlled types must be library level. This is very
unfortunate in my opinion.

> This is one instance where I'd dearly love to have an LRM reference in
> the error message...

The rule is not that all controlled types must be library level, but
that a derived tagged type cannot be nested deeper than its parent.
Ada.Finalization.Controlled is at library level, which implies that all
controlled types also must be.

The rule forbidding the nesting of derived types is very reasonable.
What I don't like is that it implies that all controlled types must be
library level.

Maybe this could be circumvented by a generic package similar to
Ada.Finalization that could be instantiated locally and provide the same
facilities as Ada.Finalization ?

Would it be feasible to write such a package for GNAT ?




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00 Controlled types in local generics? Ted Dennison
  1999-12-30  0:00 ` Mats Weber
  1999-12-30  0:00 ` Robert Dewar
@ 1999-12-30  0:00 ` Florian Weimer
  1999-12-30  0:00 ` Robert Dewar
  1999-12-30  0:00 ` Simon Wright
  4 siblings, 0 replies; 13+ messages in thread
From: Florian Weimer @ 1999-12-30  0:00 UTC (permalink / raw)


Ted Dennison <dennison@telepath.com> writes:

> Surely this isn't saying that all controlled types must be declared at
> the library level? 

What about 3.9.1(67)?




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-30  0:00   ` Ted Dennison
@ 1999-12-31  0:00     ` Robert Dewar
  1999-12-31  0:00       ` Ted Dennison
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1999-12-31  0:00 UTC (permalink / raw)


In article <386BB71D.CB7920FD@telepath.com>,
  Ted Dennison <dennison@telepath.com> wrote:
> As near as I can tell, there's no way around it.

One general approach that is typically used is to include a
controlled component in the type, rather than making the
entire structure controlled. Then the finalize routine
for that component can do whatever it needs to do. Just
think of what you would have to do if the type was derived
from some other tagged type (remember no direct MI in Ada :-)

But there are many other ways to address this in a specific
instance.

That's why I really don't consider this as a fatal flaw, merely
a minor inconvenience.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Controlled types in local generics?
  1999-12-31  0:00     ` Robert Dewar
@ 1999-12-31  0:00       ` Ted Dennison
  0 siblings, 0 replies; 13+ messages in thread
From: Ted Dennison @ 1999-12-31  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> In article <386BB71D.CB7920FD@telepath.com>,
>   Ted Dennison <dennison@telepath.com> wrote:
> > As near as I can tell, there's no way around it.
>
> One general approach that is typically used is to include a
> controlled component in the type, rather than making the
> entire structure controlled. Then the finalize routine
> for that component can do whatever it needs to do. Just
> think of what you would have to do if the type was derived
> from some other tagged type (remember no direct MI in Ada :-)

If "what it needs to do" happens to be deallocation of a
dynamicly-allocated non-library-level generic component, its not at all
clear to me how the library controlled object is going to accomplish
that. At some point unchecked_deallocation for a particular generic
object is going to have to be called by someone who has knowledge of
that generic object's type. The protected object is going to have to
have some component that lets it refer to the generic object's pointer
that isn't itself defined in a generic. But as near as I can tell
*nothing* can reference a type declared in a generic unless its is a
child of or is instantiated with that generic (and thus it also has to
be non-library level).

Quite a puzzle you have presented me with...

--
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591






^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1999-12-31  0:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-30  0:00 Controlled types in local generics? Ted Dennison
1999-12-30  0:00 ` Mats Weber
1999-12-30  0:00   ` Ted Dennison
1999-12-30  0:00   ` Robert Dewar
1999-12-30  0:00 ` Robert Dewar
1999-12-30  0:00   ` Ted Dennison
1999-12-31  0:00     ` Robert Dewar
1999-12-31  0:00       ` Ted Dennison
1999-12-30  0:00 ` Florian Weimer
1999-12-30  0:00 ` Robert Dewar
1999-12-30  0:00   ` Gautier
1999-12-30  0:00     ` Ted Dennison
1999-12-30  0:00 ` Simon Wright

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