comp.lang.ada
 help / color / mirror / Atom feed
From: sdl@MITRE-BEDFORD.ARPA
Subject: Re: Exceptions as generic parameters
Date: Mon, 6-Jul-87 10:41:47 EDT	[thread overview]
Date: Mon Jul  6 10:41:47 1987
Message-ID: <8707061441.AA10450@mitre-bedford.ARPA> (raw)
In-Reply-To: 8706291324.AA03730@mitre-bedford.ARPA


Like Dave Emery, I have often wished for the ability to define a
generic that takes an exception as a parameter.   Making the generic
definition directly visible at the point of the generic definition (either
by scope or context specification) is *not* an entirely desirable
alternative, because it may be the wrong coupling.  You often want the
exception to be grouped with the code that raises it, not with the
code that contains potential handlers for it.

However, I am concerned about the possible ambiguities/aliasing that
generic exception parameters may introduce, and whether this poses
potential problems for compiler writers.  Consider:


    generic
      E: exception;
    procedure FOO is
      X : FLOAT;
    begin
      . . . .
      X := {expression raising NUMERIC_ERROR};
    exception
      when E =>   {some handler}  ;
    end FOO;


    procedure MY_FOO_C is new FOO (E => CONSTRAINT_ERROR);
    procedure MY_FOO_N is new FOO (E => NUMERIC_ERROR);
  

In MY_FOO_C, the expression raising NUMERIC_ERROR would cause a control
transfer to the end of FOO (no handler).  In MY_FOO_N, the expression
would cause transfer to the exception handler for E (bound to
NUMERIC_ERROR).  

This means that the control flow of the generic body could not be
entirely determined when the generic is compiled.  (This might also
cause some problems with optimization of exceptions.)  Rather, some
table-driven scheme would be needed that would resolve such control
flow ambiguities at instantiation time.

The issue is whether code that raises the predefined exceptions is
compiled & optimized the same way that user-defined exceptions are
treated.  If so, then generic exception parameters shouldn't be too
difficult.

Would any Ada compiler gurus like to comment?


Steven Litvintchouk
MITRE Corporation
Burlington Road
Bedford, MA  01730
(617)271-7753

ARPA:  sdl@mitre-bedford.arpa
UUCP:  ...{cbosgd,decvax,genrad,ll-xn,philabs,security,utzoo}!linus!sdl

      reply	other threads:[~1987-07-06 14:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-06-29 13:24 Exceptions as generic parameters Emery
1987-07-06 14:41 ` sdl [this message]
replies disabled

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