From: Hacid <chadi.alkurdi@gmail.com>
Subject: Re: limited /non-limited tagged type
Date: Sat, 5 Mar 2011 08:48:11 -0800 (PST)
Date: 2011-03-05T08:48:11-08:00 [thread overview]
Message-ID: <df9383fb-7b08-4d41-b835-b6a3f411156e@a26g2000vbo.googlegroups.com> (raw)
In-Reply-To: b77e1f60-3757-44d7-a054-9067a42b18cb@y31g2000prd.googlegroups.com
On 5 mar, 04:26, Adam Beneschan <a...@irvine.com> wrote:
> After looking more closely at the OP's example code, I can think of a
> possible case where one *could* argue that a new feature in Ada would
> be useful, although I think it's way too obscure to consider adding
> anything like this.
>
> package Foo is
> type Object is tagged private;
> procedure Copy (Dest : out Object'Class; Source : in
> Object'Class);
> private
> type Object is tagged record ... end record;
> end Foo;
>
> where the body of Copy says "Dest := Source" and maybe performs some
> other functions.
>
> It wouldn't work to make the partial view of Object limited, because
> then another package could extend Object by adding a component of
> limited type to it, and then Dest := Source, when given objects of
> that new type, would copy a limited component, which is a no-no.
> However, ***IF*** Ada had a way to say that Object isn't really
> limited but still doesn't have assignment visibly defined (i.e.
> partially limited??), then things might work. Since it isn't really
> limited, it couldn't be extended with a limited component. And it
> would accomplish the purpose that the OP seems to want: forcing other
> packages to use the Copy operation (which wouldn't be overridden, but
> would still copy all the components in any type extension) instead of
> ":=". I don't know if this really is what's wanted. I'm sort of
> guessing. Anyway, I think the chance of a feature like this being
> added is somewhere between zero and less than zero, and I'm certainly
> not going to propose one.
>
> I'd still need more info on just what the OP's needs are. But if it's
> something like I guessed, then perhaps a Copy routine that takes
> Object'Class parameters instead of Object is what is wanted. And
> while there's no way to get the compiler to reject other uses of := ,
> there's a way to make them blow up at runtime: add a component to
> Object whose type is derived from Ada.Finalization.Controlled, and
> define an Adjust routine that raises an exception unless a Boolean
> flag in the body of Foo is set, and of course Copy would be the only
> routine that sets it.
>
> -- Adam
You perfectly understand what I want to do.
And I can't explain it better than you.
A good way to do that would be to derivate Object from
Ada.Finalization.Controlled. But as I said I can't due to my ZFP Run
Time use.
I was hoping that there is an other simple way to do the same... But
as Randy said I can't expect Ada to have 10 solutions to a problem.
So I think I will use non limited tagged type with primitive copy
operation and a rule checker to check "no assignement on Object class"
rule.
Thanks to yours answers and your time.
prev parent reply other threads:[~2011-03-05 16:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-04 18:56 limited /non-limited tagged type Hacid
2011-03-04 19:54 ` Edward Fish
2011-03-04 21:18 ` Hacid
2011-03-05 0:17 ` Edward Fish
2011-03-04 20:10 ` Georg Bauhaus
2011-03-04 21:55 ` Hacid
2011-03-04 22:21 ` Hacid
2011-03-05 1:20 ` Randy Brukardt
2011-03-04 22:22 ` Georg Bauhaus
2011-03-04 22:40 ` Hacid
2011-03-05 1:29 ` Georg Bauhaus
2011-03-04 23:34 ` Adam Beneschan
2011-03-05 3:26 ` Adam Beneschan
2011-03-05 16:48 ` Hacid [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox