From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Prologue and epilogue aspects
Date: Fri, 26 Jan 2018 20:56:41 +0100
Date: 2018-01-26T20:56:41+01:00 [thread overview]
Message-ID: <p4g15r$1s60$1@gioia.aioe.org> (raw)
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 <anonymous> is interface;
procedure Initialize (Object : in out <anonymous>) is
abstract with Composition => Prologue;
procedure Adjust (Object : in out <anonymous>) is
abstract with Composition => Prologue;
procedure Finalize (Object : in out <anonymous>)
abstract with Composition => Epilogue;
--
-- Old code will continue "enjoying" manual calls to parent
-- Initialize, Adjust, Finalize
--
type Controlled is abstract new <anonymous> 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 <anonymous>;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next reply other threads:[~2018-01-26 19:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-26 19:56 Dmitry A. Kazakov [this message]
2018-01-27 7:17 ` Prologue and epilogue aspects Randy Brukardt
2018-01-27 9:33 ` Dmitry A. Kazakov
2018-01-29 23:08 ` Randy Brukardt
2018-01-30 8:31 ` Dmitry A. Kazakov
2018-01-30 22:02 ` Randy Brukardt
2018-01-31 15:05 ` Dmitry A. Kazakov
2018-02-01 0:17 ` Randy Brukardt
2018-02-01 9:03 ` Dmitry A. Kazakov
2018-02-01 23:47 ` Randy Brukardt
2018-02-02 6:59 ` Niklas Holsti
2018-02-02 22:20 ` Randy Brukardt
2018-02-02 8:46 ` Dmitry A. Kazakov
2018-02-02 9:31 ` Niklas Holsti
2018-02-02 10:21 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox