File: genstatistics.perl

package info (click to toggle)
gecode 6.1.0-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 26,372 kB
  • sloc: cpp: 328,292; perl: 2,048; makefile: 1,793; sh: 214
file content (185 lines) | stat: -rw-r--r-- 5,528 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/perl
#
#  Main authors:
#     Christian Schulte <schulte@gecode.org>
#
#  Copyright:
#     Christian Schulte, 2005
#
#  This file is part of Gecode, the generic constraint
#  development environment:
#     http://www.gecode.org
#
#  Permission is hereby granted, free of charge, to any person obtaining
#  a copy of this software and associated documentation files (the
#  "Software"), to deal in the Software without restriction, including
#  without limitation the rights to use, copy, modify, merge, publish,
#  distribute, sublicense, and/or sell copies of the Software, and to
#  permit persons to whom the Software is furnished to do so, subject to
#  the following conditions:
#
#  The above copyright notice and this permission notice shall be
#  included in all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#

@modorder = ("kernel","search","int","set","float","minimodel","gist","driver",
	     "iter","support","example","test","flatzinc");

@catorder = ("core","memory","var","prop","branch","post",
	     "int","set","float","minimodel","stress","trace","any",
	     "seq","par","search","flatzinc",
	     "other");

$modclear{"kernel"} = "Kernel";
$modclear{"search"} = "Search engines";
$modclear{"gist"} = "Gist";
$modclear{"int"} = "Integer and Boolean variables and constraints";
$modclear{"set"} = "Set variables and constraints";
$modclear{"float"} = "Float variables and constraints";
$modclear{"minimodel"} = "Minimal modeling support";
$modclear{"driver"} = "Script commandline driver";
$modclear{"iter"} = "Range and value iterators";
$modclear{"support"} = "Support algorithms and datastructures";
$modclear{"example"} = "\%Example scripts";
$modclear{"test"} = "Systematic tests";
$modclear{"flatzinc"} = "FlatZinc interpreter";


$catclear{"core"} = "Core functionality";
$catclear{"memory"} = "Memory management";
$catclear{"trace"} = "Tracing support";
$catclear{"var"} = "Variables, views, and variable implementations";
$catclear{"prop"} = "Propagators";
$catclear{"branch"} = "Branchers";
$catclear{"seq"} = "Sequential search engines";
$catclear{"par"} = "Parallel search engines";
$catclear{"post"} = "Posting propagators for constraints";
$catclear{"any"} = "All";
$catclear{"other"} = "Miscellaneous";
$catclear{"int"} = "Integer and Boolean variables and constraints";
$catclear{"set"} = "Set variables and constraints";
$catclear{"float"} = "Float variables and constraints";
$catclear{"minimodel"} = "Minimal modeling support";
$catclear{"stress"} = "System stress";
$catclear{"search"} = "Search";
$catclear{"flatzinc"} = "FlatZinc interpreter";
$catclear{"ignore"} = "ignored";

#
# Get statistics for all files
#

$i = 0;

while ($file = @ARGV[$i++]) {
  open(FILE,"<$file");
  my $module = "UNKNOWN";
  my $cat    = "UNKNOWN";
  my $n_blank;
  my $n_comment;
  my $n_code;
  my $n_class;
  while ($l = <FILE>) {
    if ($l =~ /\/\/ STATISTICS: ([A-Za-z]+)-([A-Za-z]+)/) {
      $module = $1;
      $cat    = $2;
      exists $modclear{$module} or die "Module $m undefined (file $file)";
      exists $catclear{$cat} or die "Category $cat undefined (file $file)";
    }
    if ($l =~ /^[ \t]*$/) {
      $n_blank += 1;
    } elsif ($l =~ /^[ \t]*\/\//) {
      $n_comment += 1;
    } elsif ($l =~ /\/\*/) {
      $n_comment += 1;
      while (!($l =~ /\*\//) && ($l = <FILE>)) {
	$n_comment += 1;
      }
    } else {
      $n_code += 1;
    }
    if ($l =~ /class [A-Za-z_][A-Za-z0-9_]*.*\{/) {
      $n_class += 1;
    }
  }
  if ($module eq "UNKNOWN") {
    print "UNKNOWN: $file\n";
    exit 1;
  }
  $m{$module} = 1;
  $c{$cat} = 1;
  $class{"$module-$cat"} += $n_class;
  $comment{"$module-$cat"} += $n_comment;
  $blank{"$module-$cat"} += $n_blank;
  $code{"$module-$cat"} += $n_code;
  close FILE;
}

$i = 0;

print <<EOF
/**
  \\page PageCodeStat Gecode code statistics

The following approximate breakdown into the different parts of %Gecode
gives some statistics about the amount of code and documentation
contained in the code (as comments) where blank lines are excluded.

The abbreviation "loc" means "lines of code" and "lod" means "lines of
documentation".

EOF
;


$an_code    = 0;
$an_comment = 0;
$an_class   = 0;

foreach $module (@modorder) {
  print " - " . $modclear{$module} . ": ";
  $mn_code    = 0;
  $mn_comment = 0;
  $mn_class   = 0;
  $n_cat = 0;
  $doc = "";
  foreach $cat (@catorder) {
    $k = "$module-$cat";
    if ($code{$k}) {
      $n_cat += 1;
      $doc = $doc . "   - " . $catclear{$cat} . ": ";
      $mn_code    += $code{$k};
      $mn_comment += $comment{$k};
      $mn_class   += $class{$k};
      $doc = $doc .  $class{$k} . " classes, ";
      $doc = $doc .  $code{$k} . " loc, ";
      $doc = $doc .  $comment{$k} . " lod\n";
    }
  }
  print $mn_class . " classes, " . $mn_code . " loc, " . $mn_comment . " lod\n";
  if ($n_cat > 1) {
    print $doc;
  }
  $an_code    += $mn_code;
  $an_comment += $mn_comment;
  $an_class   += $mn_class;
}


print <<EOF

The grand total: $an_class classes, $an_code loc, $an_comment lod

*/
EOF
;