comp.lang.ada
 help / color / mirror / Atom feed
* Re: Using controlled types to trace program execution
@ 2002-02-27 11:55 Christoph Grein
  2002-02-27 17:59 ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Grein @ 2002-02-27 11:55 UTC (permalink / raw)


Dynamic allocation and deallocation are not necessary:

generic

  Unit_Name: String;

package Trace is

private

  X: aliased String := Unit_Name;
  Follower: T (X'Access);

end Trace;

> tmoran@acm.org wrote:
> > 
>    A combination will do the job.
> >   You can't pass a string as a discriminant to your controlled type, and if
> > you pass an access-to-string type it will be a constant and you won't
> > be able to "free" the string.  But you can do it with two levels:
> >   type p is access string;
> >   type t(msg : access p) is new ada.finalization.limited_controlled with ...
> > Then use the generic instantiation as a shorthand for declaring an
> > aliased pointer to a new string'("something") followed by a declaration
> > of the controlled type with a 'access to that pointer as its parameter.
> 
> Thanks - I hadn't thought about declaring a package - only a variable.
> 
> Nige
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Using controlled types to trace program execution
@ 2002-02-26 13:39 Nige
  2002-02-26 18:26 ` tmoran
  2002-03-06 15:20 ` Matthew Heaney
  0 siblings, 2 replies; 9+ messages in thread
From: Nige @ 2002-02-26 13:39 UTC (permalink / raw)


Hi all,

I am trying to come up with a way of tracing program execution using
controlled types. Ie, I want to be able to declare an object as a
procedure or function is entered, which would add itself to some sort of
stack during it's initialization and remove itself once it goes out of
scope.

The benfit of this is that I would not have to explicitly have some sort
of enter and exit calls whenever a subprogram is called.

The problem is, that however I try to identify the declaration of the
object, the compiler throws it out.

The approaches I have tried are:

* A controlled object with an access to a string as a discriminant.

* A generic package containing a controlled type with a discrete type as
a discriminant.

* extending the type with a string/string access to identify it.

Does anyone have any ideas how I could acomplish this or even if it is
possible? I may be trying to do something that is not sensible/possible
of course...

Ideally I'd simply like to have:

procedure Something is

  Here : Trace.Location ("Something");

begin
  null;
end Something;

 ... where the package Trace would store the string "Something" until
the object Here goes out of scope. Then at any time I can examine the
contents of the stack in the package Trace...

The nearest I have got is to use new to allocate strings as the objects
are declared, but then the strings can't be deallocated explicitly,
because the strings are not variables.
eg

  Here : Trace.Location (new String'("Something"));

Hope I've made some sense,

Nige



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

end of thread, other threads:[~2002-03-07 16:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27 11:55 Using controlled types to trace program execution Christoph Grein
2002-02-27 17:59 ` Jeffrey Carter
2002-02-28 15:24   ` Nige
  -- strict thread matches above, loose matches on Subject: below --
2002-02-26 13:39 Nige
2002-02-26 18:26 ` tmoran
2002-02-27 11:44   ` Nige
2002-03-06 15:20 ` Matthew Heaney
2002-03-07  8:56   ` Nige
2002-03-07 16:43     ` Jeffrey Carter

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