comp.lang.ada
 help / color / mirror / Atom feed
* Program identification
@ 1996-08-29  0:00 Chris Sparks
  1996-08-31  0:00 ` Ray Blaak
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Chris Sparks @ 1996-08-29  0:00 UTC (permalink / raw)



Does anyone know of a way to determine the program name within a program
without explictly making a constant for it.  If there isn't a way then
maybe a new attribute should be made for the next version of Ada, namely:

P'Identity which returns a string, P is a program unit

I am using this information as part of an exception reporter system.

BTW these would be helpful too:

P'Location which returns a string, P is a program unit and the string would
contain the current line number in the source code, or maybe even the previous
line number (for exception processing).

Any thoughts?




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

* Re: Program identification
@ 1996-08-31  0:00 tmoran
  1996-08-31  0:00 ` Robert A Duff
  0 siblings, 1 reply; 15+ messages in thread
From: tmoran @ 1996-08-31  0:00 UTC (permalink / raw)



>P'Identity which returns a string, P is a program unit
If I understand what you want, how about Ada.Command_Line.Command_Name

>P'Location which returns a string, P is a program unit and the string would
>contain the current line number in the source code, or maybe even the previous
>line number (for exception processing).
  Does Ada.Exceptions.Exception_Information do what you want?

with ada.exceptions;
with text_io;
procedure test is

  bang:exception;

  procedure badguy is
  begin raise bang; end badguy;

begin

  badguy;

exception
  when oops:bang =>
    text_io.put("egad:"
                & ada.exceptions.exception_information(oops)
                & ", whew");
end test;

  produces:

egad:TEST.BANG
   On Line Number 8 In TEST.BADGUY
Called from line number 12 In TEST
, whew




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

* Re: Program identification
  1996-08-31  0:00 Program identification tmoran
@ 1996-08-31  0:00 ` Robert A Duff
  0 siblings, 0 replies; 15+ messages in thread
From: Robert A Duff @ 1996-08-31  0:00 UTC (permalink / raw)



In article <508oqs$4jv@news2.delphi.com>,  <tmoran@bix.com> wrote:
>  produces:
>
>egad:TEST.BANG
>   On Line Number 8 In TEST.BADGUY
>Called from line number 12 In TEST
>, whew

On which version of which compiler?  (I want that compiler! ;-))

- Bob




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
  1996-08-31  0:00 ` Ray Blaak
  1996-08-31  0:00 ` Dale Stanbrough
@ 1996-08-31  0:00 ` Robert A Duff
  1996-08-31  0:00   ` Ray Blaak
  1996-09-02  0:00 ` Stephen & Tammy House
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Robert A Duff @ 1996-08-31  0:00 UTC (permalink / raw)



In article <INFO-ADA%96082914161709@LISTSERV.NODAK.EDU>,
Chris Sparks  <sparks@AISF.COM> wrote:
>P'Identity which returns a string, P is a program unit

How is:

    P'Identity

different from:

    "P"

I mean, if you know which program unit you're talking about, then you
can put its name in the program, either way.  If you don't know, then
how can you refer to it?

>I am using this information as part of an exception reporter system.

Any decent implementation of Ada.Exceptions will produce good exception
reporting info.

- Bob




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
@ 1996-08-31  0:00 ` Ray Blaak
  1996-08-31  0:00 ` Dale Stanbrough
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Ray Blaak @ 1996-08-31  0:00 UTC (permalink / raw)



Chris Sparks <sparks@AISF.COM> writes:

>P'Identity which returns a string, P is a program unit
>I am using this information as part of an exception reporter system.

I would love to have this as well, for exactly the same reason. Currently we
have program unit string constants all over the place.

Cheers,
Ray Blaak
blaak@mda.ca




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

* Re: Program identification
  1996-08-31  0:00 ` Robert A Duff
@ 1996-08-31  0:00   ` Ray Blaak
  1996-08-31  0:00     ` Robert A Duff
  0 siblings, 1 reply; 15+ messages in thread
From: Ray Blaak @ 1996-08-31  0:00 UTC (permalink / raw)



bobduff@world.std.com (Robert A Duff) writes:

>How is:
>    P'Identity
>different from:
>    "P"

P'Identity would be checked by the compiler. "P" is subject to typos, which
then gives misleading information in reporting (which are not always due to
exceptions, BTW. Consider tracing, debugging, etc.).

Cheers,
Ray Blaak
blaak@mda.ca





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

* Re: Program identification
  1996-08-31  0:00   ` Ray Blaak
@ 1996-08-31  0:00     ` Robert A Duff
  0 siblings, 0 replies; 15+ messages in thread
From: Robert A Duff @ 1996-08-31  0:00 UTC (permalink / raw)



In article <509s75$4ps@map.mda.ca>, Ray Blaak <blaak@mda.ca> wrote:
>bobduff@world.std.com (Robert A Duff) writes:
>
>>How is:
>>    P'Identity
>>different from:
>>    "P"
>
>P'Identity would be checked by the compiler. "P" is subject to typos, which
>then gives misleading information in reporting (which are not always due to
>exceptions, BTW. Consider tracing, debugging, etc.).

OK, I suppose that makes sense.  But to be useful, it seems like you
would want other stuff as well.  E.g., a way to get the caller of the
current procedure, and its caller, and so on, so you can print out all
those names.  And line numbers of the calls.  And names of all kinds of
things other than program units.  Shrug.  It seems like a lot of
information to keep around at run time, for a language like Ada.  People
already complain about the memory needed to store the tables for doing
enumeration type 'Image.

By the way, 'Identity is already used for a couple of other meanings.

- Bob




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
  1996-08-31  0:00 ` Ray Blaak
@ 1996-08-31  0:00 ` Dale Stanbrough
  1996-08-31  0:00 ` Robert A Duff
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Dale Stanbrough @ 1996-08-31  0:00 UTC (permalink / raw)



Robert A Duff writes:

"How is:

    P'Identity

different from:

    "P"
"

It would be in generics (if p'identity is defined for the
instantiation, and not the generic itself).

	with text_io; use text_io;
	generic
	procedure wow is
	begin
		put_line("my name is " & p'identity);
	end;

	procedure fred is new wow;
	...
	fred; -- outputs 'my name is fred'

I've got no idea how hard this would be, or even of its worth.
I presume you would have to include a hidden parameter to the 
generic.

Dale




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

* Re: Program identification
@ 1996-09-02  0:00 tmoran
  1996-09-03  0:00 ` Joel VanLaven
  0 siblings, 1 reply; 15+ messages in thread
From: tmoran @ 1996-09-02  0:00 UTC (permalink / raw)



>>  produces:
>>
>>egad:TEST.BANG
>>   On Line Number 8 In TEST.BADGUY
>>Called from line number 12 In TEST
>>, whew
>
>On which version of which compiler?  (I want that compiler! ;-))
  RR Software's 3.07 Ada 95.  I forget whether I ran that test on their
DOS/DPMI or Windows 95/NT, but would assume they do the same thing.




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
                   ` (2 preceding siblings ...)
  1996-08-31  0:00 ` Robert A Duff
@ 1996-09-02  0:00 ` Stephen & Tammy House
  1996-09-03  0:00 ` David C. Hoos, Sr.
  1996-09-13  0:00 ` James A. Krzyzanowski
  5 siblings, 0 replies; 15+ messages in thread
From: Stephen & Tammy House @ 1996-09-02  0:00 UTC (permalink / raw)
  To: Chris Sparks


Chris Sparks wrote:
> 
> Does anyone know of a way to determine the program name within a program
> without explictly making a constant for it.  If there isn't a way then
> maybe a new attribute should be made for the next version of Ada, namely:
> 
> P'Identity which returns a string, P is a program unit
> 
> I am using this information as part of an exception reporter system.
> 
> BTW these would be helpful too:
> 
> P'Location which returns a string, P is a program unit and the string would
> contain the current line number in the source code, or maybe even the previous
> line number (for exception processing).
> 
> Any thoughts?
Exceptions tend to be tacked on to a design.  But proper exception
definition is just as important as subprogram and parameter definitions.

Exceptions are, in fact, a set of boolean parameters passed out of a
subprogram call.  They are different in that if any of these parameters
goes high none of the rest of the data coming out of the call may mean
anything.

Your exception definitions should tell your handlers what blew up and
why.  Ada95 has a few more tricks added for exceptions than Ada83.  But,
as always, there is no substitute for a good design.




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
                   ` (3 preceding siblings ...)
  1996-09-02  0:00 ` Stephen & Tammy House
@ 1996-09-03  0:00 ` David C. Hoos, Sr.
  1996-09-13  0:00 ` James A. Krzyzanowski
  5 siblings, 0 replies; 15+ messages in thread
From: David C. Hoos, Sr. @ 1996-09-03  0:00 UTC (permalink / raw)



Chris Sparks <sparks@AISF.COM> wrote in article
<INFO-ADA%96082914161709@LISTSERV.NODAK.EDU>...
> Does anyone know of a way to determine the program name within a program
> without explictly making a constant for it.  If there isn't a way then
> maybe a new attribute should be made for the next version of Ada, namely:
> 
> P'Identity which returns a string, P is a program unit
> 
> I am using this information as part of an exception reporter system.
> 
> BTW these would be helpful too:
> 
> P'Location which returns a string, P is a program unit and the string
would
> contain the current line number in the source code, or maybe even the
previous
> line number (for exception processing).
> 
> Any thoughts?
> 
The gnat compiler has an assert mechanism which will identify source file
name and line numbers.  It is used in the compiler code itself to do just
what you describe.
It seems to me that you don't need to know the program unit name if you
know the source code location -- but I haven't seen how, or thought through
whether there is any way to identify the location of the instantiation, if
the assertion fails in a generic unit's code.
Incidentally, you need to turn on a compiler switch to activate the
assertion mechanism.
-- 
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com






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

* Re: Program identification
  1996-09-02  0:00 tmoran
@ 1996-09-03  0:00 ` Joel VanLaven
  0 siblings, 0 replies; 15+ messages in thread
From: Joel VanLaven @ 1996-09-03  0:00 UTC (permalink / raw)



tmoran@bix.com wrote:
: >>  produces:
: >>
: >>egad:TEST.BANG
: >>   On Line Number 8 In TEST.BADGUY
: >>Called from line number 12 In TEST
: >>, whew
: >
: >On which version of which compiler?  (I want that compiler! ;-))
:   RR Software's 3.07 Ada 95.  I forget whether I ran that test on their
: DOS/DPMI or Windows 95/NT, but would assume they do the same thing.

  Although I seem to have missed a number of intermediate messages, is
most definately a place where the compiler implementation makes all of the
difference.  Our PowerAda compiler gives similar "traceback" information,
as most good compilers should.  While it is not a rule in Ada, check out 
the Ada95 reference manual <11.4.1:19>, and that general area.  It states
that the exception message and information should be "useful for debugging."
Most people take that to include a "traceback" or "stack dump," but not 
nescesarily!  IMHO PowerAda has nice traceback messages, but you can judge
for yourself :)  Here is a sample program (sorry, I missed the example 
given earlier, or I would have just used that one :)  :
package b_pack is
  procedure gonna_break;
end b_pack;

package body b_pack is
  procedure gonna_break is
  a:float:=0.0;
  begin
    a:=a/a;
  end gonna_break;
end b_pack;

with b_pack; use b_pack;
procedure break_it is
begin
   gonna_break;
end break_it;


and traceback:

  Unhandled exception: CONSTRAINT_ERROR
  Message: Division by 0 (LRM 4.5.5:12)

  Traceback:
Raised in b_pack:gonna_break at line: 9
Raised in break_it:break_it at line: 16
Raised in <Main Environment Task> at line: 0

  One interesting question is what to call a procedure/subprogram when
generics are involved.  For instance, if make two instantiations of
float_io, fio and myfloat_io, is the name of the put procedure for
exceptions fio.put and myfloat_io.put, float_io.put, or something even
more complicated like <fio>.put (float_io) ?  These are decisions that
the language did not decide on, they were left to the implementors, for
better or for worse.
-- 
-- Joel VanLaven




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

* Re: Program identification
  1996-08-29  0:00 Chris Sparks
                   ` (4 preceding siblings ...)
  1996-09-03  0:00 ` David C. Hoos, Sr.
@ 1996-09-13  0:00 ` James A. Krzyzanowski
  1996-09-14  0:00   ` Ken Garlington
  5 siblings, 1 reply; 15+ messages in thread
From: James A. Krzyzanowski @ 1996-09-13  0:00 UTC (permalink / raw)



Chris Sparks (sparks@AISF.COM) wrote:
: Does anyone know of a way to determine the program name within a program
: without explictly making a constant for it.  If there isn't a way then
: maybe a new attribute should be made for the next version of Ada, namely:

: P'Identity which returns a string, P is a program unit

: I am using this information as part of an exception reporter system.

: BTW these would be helpful too:

: P'Location which returns a string, P is a program unit and the string would
: contain the current line number in the source code, or maybe even the
: previous line number (for exception processing).

: Any thoughts?

Using Alsys Ada on an HP/UX platform, it would be...

System_Environment.Arg_Value (Index => 0);

--
Not necessarily the opinion of the company...
--
---------------------------------------------------------------------------
         James A. Krzyzanowski - Senior Software Engineer - AFATDS
   Hughes Defense Communications * Fort Wayne, IN 46808 * (219) 429-6446
   ^^^ the company formerly known as Magnavox Electronic Systems Company
Internet: jakrzy@most.fw.hac.com * AOL: JimShiz@AOL.com * MOST: jakrzy@most
     "I'd rather be right than politically correct !!!" - Rush is Right
---------------------------------------------------------------------------




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

* Re: Program identification
  1996-09-13  0:00 ` James A. Krzyzanowski
@ 1996-09-14  0:00   ` Ken Garlington
  1996-09-15  0:00     ` Larry Kilgallen
  0 siblings, 1 reply; 15+ messages in thread
From: Ken Garlington @ 1996-09-14  0:00 UTC (permalink / raw)



James A. Krzyzanowski wrote:
> 
> Chris Sparks (sparks@AISF.COM) wrote:
> : Does anyone know of a way to determine the program name within a program
> 
> Using Alsys Ada on an HP/UX platform, it would be...
> 
> System_Environment.Arg_Value (Index => 0);

I assume this is the same as Ada.Command_Line.Command_Name?

-- 
LMTAS - "Our Brand Means Quality"




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

* Re: Program identification
  1996-09-14  0:00   ` Ken Garlington
@ 1996-09-15  0:00     ` Larry Kilgallen
  0 siblings, 0 replies; 15+ messages in thread
From: Larry Kilgallen @ 1996-09-15  0:00 UTC (permalink / raw)



In article <323AC25C.722@lmtas.lmco.com>, Ken Garlington <garlingtonke@lmtas.lmco.com> writes:
> James A. Krzyzanowski wrote:
>> 
>> Chris Sparks (sparks@AISF.COM) wrote:
>> : Does anyone know of a way to determine the program name within a program
>> 
>> Using Alsys Ada on an HP/UX platform, it would be...
>> 
>> System_Environment.Arg_Value (Index => 0);
> 
> I assume this is the same as Ada.Command_Line.Command_Name?

But if so, then it should not be taken as "program name"
by the programmer, as it would merely represent whatever
the user had chosen to call the program, suitable only
for displaying back to the user. It could _not_ be used
to determine whether this unit was currently linked into
the toaster-pop program or the missile-launch program
(same general concept, but on differing scale and requiring
different levels of authentication - we hope).

Larry Kilgallen




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

end of thread, other threads:[~1996-09-15  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-31  0:00 Program identification tmoran
1996-08-31  0:00 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1996-09-02  0:00 tmoran
1996-09-03  0:00 ` Joel VanLaven
1996-08-29  0:00 Chris Sparks
1996-08-31  0:00 ` Ray Blaak
1996-08-31  0:00 ` Dale Stanbrough
1996-08-31  0:00 ` Robert A Duff
1996-08-31  0:00   ` Ray Blaak
1996-08-31  0:00     ` Robert A Duff
1996-09-02  0:00 ` Stephen & Tammy House
1996-09-03  0:00 ` David C. Hoos, Sr.
1996-09-13  0:00 ` James A. Krzyzanowski
1996-09-14  0:00   ` Ken Garlington
1996-09-15  0:00     ` Larry Kilgallen

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