comp.lang.ada
 help / color / mirror / Atom feed
* Prologue and epilogue aspects
@ 2018-01-26 19:56 Dmitry A. Kazakov
  2018-01-27  7:17 ` Randy Brukardt
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2018-01-26 19:56 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-02-02 22:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26 19:56 Prologue and epilogue aspects Dmitry A. Kazakov
2018-01-27  7:17 ` 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

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