From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e5138de1ea5afeb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-26 10:27:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newscon02.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr14.news.prodigy.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Using controlled types to trace program execution References: <3C7B9007.FB5F257D@uk.thalesgroup.com> X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 67.115.104.190 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr14.news.prodigy.com 1014748018 ST000 67.115.104.190 (Tue, 26 Feb 2002 13:26:58 EST) NNTP-Posting-Date: Tue, 26 Feb 2002 13:26:58 EST Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: Q[R_PJONAJUMB_LY@BCBNWX@RJ_XPDLMN@GZ_GYO^JWTEPIB_NVUAH_[BL[\IRKIANGGJBFNJF_DOLSCENSY^U@FRFUEXR@KFXYDBPWBCDQJA@X_DCBHXR[C@\EOKCJLED_SZ@RMWYXYWE_P@\\GOIW^@SYFFSWHFIXMADO@^[ADPRPETLBJ]RDGENSKQQZN Date: Tue, 26 Feb 2002 18:26:58 GMT Xref: archiver1.google.com comp.lang.ada:20469 Date: 2002-02-26T18:26:58+00:00 List-Id: > 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 > ... > * 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 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. Your compiler vendor may supply an easier way of tracing execution. If you really need to do it this way, here's a working example: with ada.finalization; package trt is type p is access string; type t(msg : access p) is new ada.finalization.limited_controlled with null record; procedure initialize(x: in out t); procedure finalize(x: in out t); end trt; with ada.text_io; with ada.unchecked_deallocation; package body trt is procedure initialize(x: in out t) is begin ada.text_io.put_line("init " & x.msg.all.all); end initialize; procedure free is new ada.unchecked_deallocation(string,p); procedure finalize(x: in out t) is begin ada.text_io.put_line("fini " & x.msg.all.all); free(x.msg.all); end finalize; end trt; with trt; generic msg : string; package trace is private x : aliased trt.p := new string'(msg); follower : trt.t(x'access); end trace; -- usage with ada.text_io; with trace; procedure trtest is procedure p1 is package tracer is new trace("trace p1"); begin ada.text_io.put_line("in p1"); end p1; procedure p2 is package tracer is new trace("trace p2"); begin ada.text_io.put_line("start p2"); p1; ada.text_io.put_line("end p2"); end p2; begin p1; p2; end trtest;