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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Prologue and epilogue aspects Date: Fri, 26 Jan 2018 20:56:41 +0100 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: Rjuo3Pbd1yFgv8E/Xizs9A.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US X-Mozilla-News-Host: news://news.aioe.org:119 Xref: reader02.eternal-september.org comp.lang.ada:50165 Date: 2018-01-26T20:56:41+01:00 List-Id: While we are at [limited] controlled interfaces why not to make them safer? I would propose a simple aspect Composition for primitive procedures (including interfaces). The aspect has values: Prologue | Override (default) | Epilogue | Final procedure First (...) with Composition => Prologue; when overridden the parent type's body is called before the override. procedure Last (...) with Composition => Epilogue; when overridden the parent's body is called after successful completion of the override. procedure Always (...) with Composition => Final; when overridden the parent's body is always called after completion of the override. The exceptions from the override are re-raised after successful execution of the body. The aspect is inherited if overriding does not change it. [Variant: the aspect cannot be changed if the override does not have a full view of the type.] The aspect inherited from interfaces is overridden by the aspect inherited from a full type [diamond inheritance]. Conflicting aspects from multiple interfaces must be explicitly overridden. ---------------------------------------------------------------- Now Ada.Finalization will declare Controlled as follows: type is interface; procedure Initialize (Object : in out ) is abstract with Composition => Prologue; procedure Adjust (Object : in out ) is abstract with Composition => Prologue; procedure Finalize (Object : in out ) abstract with Composition => Epilogue; -- -- Old code will continue "enjoying" manual calls to parent -- Initialize, Adjust, Finalize -- type Controlled is abstract new with private; overriding procedure Initialize (Object : in out Controlled) is null with Composition => Override; overriding procedure Adjust (Object : in out Controlled) is null with Composition => Override; overriding procedure Finalize (Object : in out Controlled) is null with Composition => Override; -- -- New code with have things as they should have been -- type Controlled_Interface is new ; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de