comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Trying to understand Ada.Finalization.Controlled assignment mechanics.
Date: Mon, 22 Sep 2014 18:17:13 -0700
Date: 2014-09-22T18:17:13-07:00	[thread overview]
Message-ID: <lvqhmp$rbc$1@dont-email.me> (raw)
In-Reply-To: <024b1649-e056-4b7a-9072-7c7ef0c53f0b@googlegroups.com>

On 09/22/2014 05:43 PM, Jeremiah wrote:
> My understanding of assignment of a child of Ada.Finalization.Controlled is that if you do the following:
> 
> A := B;  -- A and B are derived from Ada.Finalization.Controlled
> 
> That the following occurs:
> Finalize(A);
> Copy B into A;
> Adjust(B);
> 
> Is this correct?

Not necessarily. This is an assignment statement. ARM 7.6(17) says

'For an assignment_statement, after the name and expression have been evaluated,
and any conversion (including constraint checking) has been done, an anonymous
object is created, and the value is assigned into it; that is, the assignment
operation is applied. (Assignment includes value adjustment.) The target of the
assignment_statement is then finalized. The value of the anonymous object is
then assigned into the target of the assignment_statement. Finally, the
anonymous object is finalized. As explained below, the implementation may
eliminate the intermediate anonymous object, so this description subsumes the
one given in 5.2, “Assignment Statements”.'

So it could be

Create C (the anonymous object);
Copy B into C;
Adjust (C);
Finalize (A);
Copy C into A;
Adjust (A);
Finalize (C);

If the anonymous object is optimized away, then it becomes your sequence.

>    tester : test_class2.test := test_class2.Make(new Integer'(45));
>
> The output I am seeing doesn't make sense to me:
> Adjusting
> Finalizing  (FREED)
> Adjusting
> Finalizing
> Hello World
> Finalizing

Your test example is complicated by the use of the function and the aggregate
inside it.  Someone with a better understanding of GNAT's handling of controlled
objects should probably comment on this. But it might be a good idea to start
with a simpler test case, involving no initialization, functions, aggregates, or
access types, and then complicate it step by step.

ARM 7.6(17.1/3) says

'When a function call or aggregate is used to initialize an object, the result
of the function call or aggregate is an anonymous object, which is assigned into
the newly-created object.'

My guess is that there are both an aggregate object and function return object.
The aggregate object is copied into the function return object (FRO), the FRO is
adjusted, and the aggregate object is finalized. The the FRO is copied into
Tester, Tester is adjusted, and the FRO is finalized. The body of the main
procedure is then executed, and Tester is finalized. But I could be way off.

http://www.adaic.org/resources/add_content/standards/12rm/html/RM-7-6.html

-- 
Jeff Carter
"Blessed are they who convert their neighbors'
oxen, for they shall inhibit their girth."
Monty Python's Life of Brian
83


  reply	other threads:[~2014-09-23  1:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23  0:43 Trying to understand Ada.Finalization.Controlled assignment mechanics Jeremiah
2014-09-23  1:17 ` Jeffrey Carter [this message]
2014-09-23 16:08   ` Jeremiah
2014-09-23 16:23     ` Adam Beneschan
2014-09-23 17:39       ` Simon Wright
2014-09-23 17:50     ` Jeffrey Carter
2014-09-23 19:19     ` Robert A Duff
2014-09-23 21:59       ` Jeremiah
2014-09-24 10:59         ` AdaMagica
replies disabled

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