comp.lang.ada
 help / color / mirror / Atom feed
* Ada Code Formatting (Ada source diff)
@ 1996-09-05  0:00 Franco Mazzanti
  1996-09-06  0:00 ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Franco Mazzanti @ 1996-09-05  0:00 UTC (permalink / raw)



Some time ago on this thread it has been said (by Robert Dewar?):

> A useful utility would be an Ada specific diff, with an option to ignore
> white space, ignore line changes, ignore reformatting of comments, or
> igore comments completely.
>

Supposing GNAT is installed, the following simple CSH script, compares
the sources of two files containing a set of compilation units, and
report any difference which is not due to indenting, casing or comments.
It has been tested on Sun/Solaris1 but should be easily portable to any
Unix system since if just calls gnatchop, gnatf and diff.

Franco Mazzanti

----------------------- cut and make executable ---------------------------
#!/bin/csh
############################################################################
# src-diff
#    :compares the Ada sources inside two files omitting the
#    differences caused by indentations, case of identifiers or comments
#
# assumes gnatf and gnatchop are properly installed and visible through PATH
# assumes "diff" is available
############################################################################

if ($#argv == '0' || $#argv == '1') then
   echo 'usage: src-diff <file1> <file2>'
   exit
endif

set dir1=/tmp/$$src1
set dir2=/tmp/$$src2
mkdir $dir1
mkdir $dir2

gnatchop $1 $dir1  >/dev/null
gnatchop $2 $dir2  >/dev/null

cd $dir1
foreach unit (`/bin/ls *.ad?`)
  gnatf -s -do ${dir1}//$unit > ${dir1}/$unit.do
  gnatf -s -do ${dir2}/$unit > ${dir2}/$unit.do
  diff ${dir1}/$unit.tree  ${dir2}/$unit.do
end

/bin/rm -r $dir1 $dir2

############################################################################




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

* Re: Ada Code Formatting (Ada source diff)
  1996-09-05  0:00 Ada Code Formatting (Ada source diff) Franco Mazzanti
@ 1996-09-06  0:00 ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-09-06  0:00 UTC (permalink / raw)



The given script is neither reliable (two different programs can give
the same -do output -- for example 16#1# will look the same as 9#1#))

nor is the differences that you get very useful if there is no match
(line numbers are wrong ...)

The output of course is not useful in doing a patch either.

So while this script has some value as an approximate check, it does
not obviate the utility of a more intelligent Ada diff program!





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

* Re: Ada Code Formatting (Ada source diff)
  1996-09-06  0:00 Franco Mazzanti
@ 1996-09-06  0:00 ` Robert Dewar
  1996-09-06  0:00 ` Robert Dewar
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-09-06  0:00 UTC (permalink / raw)



incidentally, I think it is a clever trick of Franco's to (mis)use the
-gnato output in this way. Maybe we will try to document what the
limitations (or useful functionality, depending on your point of view)
are! :-)





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

* Re: Ada Code Formatting (Ada source diff)
  1996-09-06  0:00 Franco Mazzanti
  1996-09-06  0:00 ` Robert Dewar
@ 1996-09-06  0:00 ` Robert Dewar
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-09-06  0:00 UTC (permalink / raw)



Franco Mazzanti said:

"This, actually, could be seen as a feature, when it documented inside the
script, rather then a bug.

Is there any other really meaningful difference which is lost, (apart from
not distinguing the literals 01, 001, 0001, 2#1#, 4#1#, and similars)?"

The point is that there is no reliable answer to this question. The only
guarantee on -gnatdo (-do in gnatf) is that the output is equivalent 
semanmtically to the original source. Note that this is more than just
a debugging feature, since this same circuit is used for distribution
stub generation, so it is certainly not going away, and I agree that
from one point of view the normalization done by -gnato could be
seen as a feature. Another case is large numbers of parens result in
paren layers being ignored, e.g. (((((((b))))))) is the same as (((b))).
There many be others, I simply don't know since there is no requirement
to think about this or document it!





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

* Re: Ada Code Formatting (Ada source diff)
@ 1996-09-06  0:00 Franco Mazzanti
  1996-09-06  0:00 ` Robert Dewar
  1996-09-06  0:00 ` Robert Dewar
  0 siblings, 2 replies; 5+ messages in thread
From: Franco Mazzanti @ 1996-09-06  0:00 UTC (permalink / raw)



Robert wrote:

> The given script is neither reliable (two different programs
> can give the same -do output -- for example 16#1# will look the same as 9#1#))

This, actually, could be seen as a feature, when it documented inside the
script, rather then a bug.

Is there any other really meaningful difference which is lost, (apart from
not distinguing the literals 01, 001, 0001, 2#1#, 4#1#, and similars)?

> 
> nor is the differences that you get very useful if there is no match
> (line numbers are wrong ...)

True, they are related to the gnatf -s -do output. In case of mismatch,
however, we might avoid to delete the gnatf output and give the user the
names of the two gnatf-dumped output so that it were possible to look inside
them for getting a more complete understanding of line numbers.

> 
> The output of course is not useful in doing a patch either.
> 

I have the impression that the possibility of performing a patch would
not be very meaningful in this case.
The real purpose of the script is just to allow an easy verification that 
a simple maintenance operation (or pretty-printing) did not inadvertedly 
modify the code. 
This is not thought as an utility which compares different versions of a
program. Probably the name should be changed, since "diff" implicitly
carries that other stronger meaning (maybe we could call it
"src-equiv", "src-compare", ....).

> So while this script has some value as an approximate check, it does
> not obviate the utility of a more intelligent Ada diff program!

Sure, this was not considered a perfect solution, just a very simple one.
A more intellingent tool might, for example, do not consider as a
difference the removal of unnecessary code, and many other intelligent things.

The main problem of this approach is that the "-do" switch is not an
official gnatf feature, but just an internal debugging option. This means
that there is no guarantee that the switch will exist in future versions
of gnatf, or its effect could be completely different. This also should be noted
in the script (which doesn not even specify with which version of gnat it
supposes to find).

Franco




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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-05  0:00 Ada Code Formatting (Ada source diff) Franco Mazzanti
1996-09-06  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-09-06  0:00 Franco Mazzanti
1996-09-06  0:00 ` Robert Dewar
1996-09-06  0:00 ` Robert Dewar

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