comp.lang.ada
 help / color / mirror / Atom feed
* Perl script to show dependencies
@ 1996-10-05  0:00 Rolf Ebert
  1996-10-10  0:00 ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Rolf Ebert @ 1996-10-05  0:00 UTC (permalink / raw)



The following is a simple minded perl-script which analyses Ada files
and generates a spreadsheet of the dependencies between the Ada units.
I wrote it, because I wanted to know about the relation between several
units before reorganizing a project.

The script is very limited in several aspects.  

1) It requires the GNAT naming scheme without any "krunching",
i.e. specs are in *.ads, bodies are in *.adb and the filename
corresponds to the name of the unit. 

2) It requires that a with statement references a single unit.  If you
write

with Toto, Tata;

it will list only Toto as a unit on which the current one depends.  My
personal style is to write a new with statement for every unit.  If that
is not your style, don't use this script (or better send me a patch
which makes it working with your style)

3) all files must be present in the current directory.


The output is a comma separated ascii file (on stdout) which can be read
by most spreadsheet programs (Excel, StarCalc, ...).  The top line lists
all units on which others depend.  On the left you have all files (specs
and bodies) in alphabetical order.  The matrix element is either empty
(no dependency), contains a "w" (the file on the left explicitely
"withes" the unit on the top, parents included), and/or a "p" (the unit
on the top is a parent of the unit on the left)

It will show only explicit dependancies from "withing" or from being a
child.  No dependancy created by the compiler (generics, inlineing) is
shown.


Please mail me if you think the script is useful.

        Rolf
        ebert@waporo.muc.de


---------------------------------------------------------------
#!/opt/gnu/bin/perl

# generate a spreadsheet of explicit dependancies between Ada units

opendir(DIR, ".");
@specfiles = grep(/\.ads$/, readdir(DIR));
rewinddir(DIR);
@bodyfiles = grep(/\.adb$/, readdir(DIR));
closedir(DIR);

## Loop over all files.  Files are scanned for with clauses.  With
## clauses are supposed to have only one entry, which is on the same
## line as the "with" keyword itself.  
##
## Dependancy on parent packages is deduced from the filename itself.
## This algorithm assumes GNAT filename conventions without
## "krunching".
##

foreach $file (@specfiles, @bodyfiles) {
    open(FILE, $file) || warn "Cannot open file $file: $!.";

    # replace the dot of the file extension by a blank for sorting
    $file =~ tr/./ /;

    # We add units withed by the spec to the body as well.
    if (substr($file, -1) eq "s") { 
        $body = substr($file, 0, length($file)-1) . "b";
    } else {
        $body = $file;
        substr($file, -1) = "z";
    }

    while (<FILE>) {
        if (/^with\s+([\w\.]+)/) {
            $ref = $1;
            $ref =~ tr/A-Z/a-z/; # convert to lower case
            $depends_on{$ref}->{$file} = "w";
            if ($body) { $depends_on{$ref}->{$body} = "w"; }

            # all parent units of withed units are withed as well
            $p = rindex($ref, ".");
            while ($p >= $[) { # there is a "." in ref
                $ref = substr($ref, $[, $p); # extract leading part
                $depends_on{$ref}->{$file} = "w";
                if ($body) { $depends_on{$ref}->{$body} = "w"; }
                $p = rindex($ref, ".");
            }
        }
    }

    # unit depends on all own parents
    $ref = $file;
    $p = rindex($ref, " ");
    $ref = substr($ref, $[, $p); # ommit file extension
    $ref =~ tr/-/./;
    $p = rindex($ref, ".");
    while ($p >= $[) { # there is a "." in ref
        $ref = substr($ref, $[, $p); 
        if (substr($file, -1) eq "z") {
            $depends_on{$ref}->{$body} .= "p";
        } else {
            $depends_on{$ref}->{$file} .= "p";
        }
        $p = rindex($ref, ".");
    }

    close(FILE);
}



## print out the matrix
@sorted_keys = sort(keys(%depends_on));
foreach $unit (@sorted_keys) {
    print ";$unit";
}
print ";\n";

foreach $file (sort(@specfiles,@bodyfiles)) {
      if (substr($file, -1) eq "z") { 
          # rename bodyfiles back to original name
          substr($file, -1) = "b";
      }

    print "$file;";
    foreach $unit (@sorted_keys) {
        print $depends_on{$unit}->{$file};
        print ";";
    }
    print "\n";
}
    

---------------------------------------------------------------------------




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

* Re: Perl script to show dependencies
  1996-10-05  0:00 Perl script to show dependencies Rolf Ebert
@ 1996-10-10  0:00 ` Robert Dewar
  1996-10-12  0:00   ` Keith Thompson
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Robert Dewar @ 1996-10-10  0:00 UTC (permalink / raw)



Rolf said

"The following is a simple minded perl-script which analyses Ada files
and generates a spreadsheet of the dependencies between the Ada units.
I wrote it, because I wanted to know about the relation between several
units before reorganizing a project."

Wouldn't it be better to use the dependency information in the ali files,
because then you would pick up inlining and generic body dependencies as
well.





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

* Re: Perl script to show dependencies
  1996-10-10  0:00 ` Robert Dewar
@ 1996-10-12  0:00   ` Keith Thompson
  1996-10-20  0:00   ` Richard Riehle
  1996-10-21  0:00   ` Rolf Ebert
  2 siblings, 0 replies; 6+ messages in thread
From: Keith Thompson @ 1996-10-12  0:00 UTC (permalink / raw)



In <dewar.844959342@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
> Rolf said
> 
> "The following is a simple minded perl-script which analyses Ada files
> and generates a spreadsheet of the dependencies between the Ada units.
> I wrote it, because I wanted to know about the relation between several
> units before reorganizing a project."
> 
> Wouldn't it be better to use the dependency information in the ali files,
> because then you would pick up inlining and generic body dependencies as
> well.

What ali files?  There are Ada 95 compilers other than GNAT, you know.
8-)}

-- 
Keith Thompson (The_Other_Keith) kst@thomsoft.com <*>
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
FIJAGDWOL




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

* Re: Perl script to show dependencies
  1996-10-10  0:00 ` Robert Dewar
  1996-10-12  0:00   ` Keith Thompson
@ 1996-10-20  0:00   ` Richard Riehle
  1996-10-21  0:00   ` Rolf Ebert
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Riehle @ 1996-10-20  0:00 UTC (permalink / raw)




On 10 Oct 1996, Robert Dewar wrote:

> Rolf said
> 
> "The following is a simple minded perl-script which analyses Ada files
> and generates a spreadsheet of the dependencies between the Ada units.
> I wrote it, because I wanted to know about the relation between several
> units before reorganizing a project."
> 
> Wouldn't it be better to use the dependency information in the ali files,
> because then you would pick up inlining and generic body dependencies as
> well.

  But not all ada programs are compiled under GNAT, so .ali files 
  might not be a portable use of Rolf's Perl script.

  Richard Riehle





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

* Re: Perl script to show dependencies
  1996-10-10  0:00 ` Robert Dewar
  1996-10-12  0:00   ` Keith Thompson
  1996-10-20  0:00   ` Richard Riehle
@ 1996-10-21  0:00   ` Rolf Ebert
  1996-10-24  0:00     ` Too many WITH's? (was: Perl script to show dependencies) Adam Beneschan
  2 siblings, 1 reply; 6+ messages in thread
From: Rolf Ebert @ 1996-10-21  0:00 UTC (permalink / raw)



On 10 Oct 1996, Robert Dewar wrote:

> Rolf said
> 
> "The following is a simple minded perl-script which analyses Ada files
> and generates a spreadsheet of the dependencies between the Ada units.
> I wrote it, because I wanted to know about the relation between several
> units before reorganizing a project."
> 
> Wouldn't it be better to use the dependency information in the ali files,
> because then you would pick up inlining and generic body dependencies as
> well.

I was not interested in the dependancies which concern the compiler, but
in the logical dependancies between the modules.  I wanted to apply the
rule of a thumb saying "if there are too many with clauses (~> 8), think
about your design".  

Even for that pupose it might be a good idea to use the ALI files as
they reliably contain *all* with clauses (lines starting with W) whereas
my script is limited to a certain style for writing with clauses.


        Rolf
        ebert@waporo.muc.de




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

* Too many WITH's? (was: Perl script to show dependencies)
  1996-10-21  0:00   ` Rolf Ebert
@ 1996-10-24  0:00     ` Adam Beneschan
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 1996-10-24  0:00 UTC (permalink / raw)



In article <m2lod09lv8.fsf@waporo.muc.de> Rolf Ebert <re@waporo.muc.de> writes:

 >I was not interested in the dependancies which concern the compiler, but
 >in the logical dependancies between the modules.  I wanted to apply the
 >rule of a thumb saying "if there are too many with clauses (~> 8), think
 >about your design".  

Just curious--where does this rule of thumb come from?  Also, does it
apply to Ada 83, or just Ada 95?  (It does make a difference, since
tagged types and child packages could make it easier to break down a
module into smaller cohesive units that don't have as many
dependencies.) 

Naturally, I do follow this rule of thumb literally, since I'm always
thinking about my design anyway regardless of how many WITH clauses
there are.  :) Seriously, though, I'd never heard that having more
than eight WITH clauses was either undesirable in itself, nor that it
was an indicator of some undesirable feature of the design that needed
looking into.  (I think I have heard a similar rule of thumb in
connection with "top-down design", but that dates from a time when the
only modules were subprograms, not packages, so I wonder whether the
rule should still apply.)

                                -- thanks, Adam





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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-05  0:00 Perl script to show dependencies Rolf Ebert
1996-10-10  0:00 ` Robert Dewar
1996-10-12  0:00   ` Keith Thompson
1996-10-20  0:00   ` Richard Riehle
1996-10-21  0:00   ` Rolf Ebert
1996-10-24  0:00     ` Too many WITH's? (was: Perl script to show dependencies) Adam Beneschan

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