From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7fcf9180e7ba7ab1,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!kanaga.switch.ch!switch.ch!news.belwue.de!LF.net!news.enyo.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: A suggestion for resource management Date: Sat, 21 Aug 2010 18:20:29 +0200 Message-ID: <8762z4gcoi.fsf@mid.deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: idssi.enyo.de 1282407629 2879 172.17.135.6 (21 Aug 2010 16:20:29 GMT) X-Complaints-To: news@enyo.de Cancel-Lock: sha1:ZKYEpGyJT5w4WKjJTGC2gPOSqYY= Xref: g2news1.google.com comp.lang.ada:13579 Date: 2010-08-21T18:20:29+02:00 List-Id: 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;