comp.lang.ada
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
Subject: A suggestion for resource management
Date: Sat, 21 Aug 2010 18:20:29 +0200
Date: 2010-08-21T18:20:29+02:00	[thread overview]
Message-ID: <8762z4gcoi.fsf@mid.deneb.enyo.de> (raw)

Here's a proposal for a resource management pragma, tentatively called
pragma Scoped.  It is similar to the scope(exit) directive in D, the
C++ scope guard idom, and (to a lesser degree) Go's rescue statement.

The syntax is:

   pragma Scoped (procedure_call_statment);

The legality rules and static semantics are the same as for the old
(one-argument) pragma Debug implemented by GNAT, with the additional
restriction that Scoped pragmas may only appear in a
handled_sequence_of_statements or in a declarative_part.  (This
additional restriction is necessary because otherwise, the pragma
could be executed multiple times, and it is difficult to decide what
should happen in this case.)

Regarding dynamic semantics: When a Scoped pragma which is part of a
handled_sequence_of_statements is executed or when it is elaborated as
part of a declarative_part, the procedure_name or procedure_prefix and
actual parameters of the procedure_call_statment are evaluated.

If the corresponding handled_sequence_of_statements completes
subsequently (or if the declarative_part completes abnormally, without
ever entering the handled_sequence_of_statements), the procedure call
is performed, using the prefix and parameters as evaluated previously.
After that, objects are finalized as necessary.  (Finalization of
parameters is a reason why there are no specific pragmas for normal
and abnormal completion---the arguments would have to be finalized,
despite the pragma suggesting that nothing happens in that case.)  The
procedure calls happen in the reverse order of the execution of the
pragmas, and before objects are finalized which were elaborated prior
to execution of the pragma.

If the procedure call itself completes abnormally, Program_Error is
raised.  (Program_Error is not raised if the earlier parameter
evaluation completes abnormally.)

The example at the end of section B.4 could use the Scoped pragma in
this way:

          procedure Test_External_Formats is
             ...
             COBOL_File : File_Type;
             ...

          begin
             Open (COBOL_File, Name => "Some_File");
             pragma Scoped (Close (COBOL_File));

             loop
               ...
          exception
             when End_Error => ...
          end Test_External_Formats;



             reply	other threads:[~2010-08-21 16:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21 16:20 Florian Weimer [this message]
2010-08-21 19:07 ` A suggestion for resource management Dmitry A. Kazakov
2010-08-21 19:47   ` Florian Weimer
2010-08-21 20:53     ` Dmitry A. Kazakov
2010-08-21 21:09       ` Florian Weimer
2010-08-22  6:40         ` Dmitry A. Kazakov
2010-08-23 23:22         ` Randy Brukardt
2010-08-21 20:34 ` Niklas Holsti
2010-08-21 21:01   ` Florian Weimer
2010-08-22 10:53     ` Niklas Holsti
2010-08-22 15:29       ` Florian Weimer
2010-08-22 16:12       ` Florian Weimer
2010-08-23 12:25         ` Niklas Holsti
2010-09-04 19:09           ` Florian Weimer
2010-09-07 10:14             ` Niklas Holsti
2010-08-22 11:32     ` Georg Bauhaus
2010-08-23 23:37       ` Randy Brukardt
2010-08-22 13:09 ` stefan-lucks
2010-08-22 14:30   ` Florian Weimer
2010-08-22 15:09   ` Florian Weimer
replies disabled

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