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-Thread: 103376,400766bdbcd86f7c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!usenet-fr.net!enst.fr!not-for-mail From: Jerome Hugues Newsgroups: comp.lang.ada Subject: Re: This can't be done in Ada...or? Date: Fri, 11 Feb 2005 17:08:04 +0000 (UTC) Organization: ENST, France Message-ID: References: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: nephilim.enst.fr X-Trace: avanie.enst.fr 1108141684 3135 137.194.160.16 (11 Feb 2005 17:08:04 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 11 Feb 2005 17:08:04 +0000 (UTC) User-Agent: slrn/0.9.7.3 (SunOS) Xref: g2news1.google.com comp.lang.ada:8248 Date: 2005-02-11T17:08:04+00:00 List-Id: In article <1108139611.709714.36170@o13g2000cwo.googlegroups.com>, Per Lindquist wrote: > My impression from reading some threads is that Ada DOES NOT offer a > decent way to implement trace printouts (log messages), at least not > with the features stated below. Where did you read that ? > We want to be able to output log messages, or traces as we call it, > from an Ada program. There will be a few trace categories like Error, > Warning, Note etc. The messages (strings) can be sent to a file or > stdout or whatever (not important). > > A call might look something like this: > > Trace.Error(Package_Name, Subprogram_Name, "Woops, V=" & > Some_Type'Image(V)); > > How do we write a tracing utility in Ada that: > 1. has different behaviour on different target platforms => provide one body/target + GNAT project files > 2. can disable some categories depending on target platform at > compile-time. => build a spec-only package that looks like package My_Flags is Feature_1 : constant Boolean := False; end My_Flags In the implementation of Trace.Error, use My_Flags.Feature_x to disable code. Any decent (all ?) Ada compiler should remove all "if False then .. end if;" blocks at compile-time > 3. does *not* cause any execution overhead if disabled. => pragma Debug (Trace.Error ..); (GNAT specific) > 4. does not need yucky "if Trace_Wanted then ... end if;" around all > calls => pragma Debug .. > 5. does not need preprocessing (some of you say it's never needed in > Ada...) => My solution doesn't, yet it requires tweaking your compilation process so that you can select the correct package depending on your configuration. > I say it can't be done in Ada. Please prove me wrong! You can, but I confess my solution is in part vendor specific. The only kludge is the one body/implementation, GNAT project files should handle this easily. > If we could get rid of those hardcoded constants > > Package_Name : constant String := "Some_Package"; > ... > Subprogram_Name : constant String := "Some_Procedure1"; > ... > Subprogram_Name : constant String := "Some_Procedure2"; > > it would be a great bonus, but I reckon it can't be done either..? See GNAT.Source_Info in your code, just try Ada.Text_IO.Put_Line (GNAT.Source_Info (Source_Location)); and see the magic occurs. GNAT.Source_Info is the equivalent of __FILE__, __LINE__ macros from C. -- Jerome