Heuristic perl script to check for proper use of compensations.
This commit is contained in:
parent
fdf5344ec3
commit
f68e6b9dd3
2 changed files with 84 additions and 0 deletions
80
utilities/check_compensations
Executable file
80
utilities/check_compensations
Executable file
|
@ -0,0 +1,80 @@
|
|||
#! /usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
my @header = `find . -name '*.h'`;
|
||||
my @source = `find . -name '*.c'`;
|
||||
|
||||
my %h;
|
||||
my $nest = 0;
|
||||
|
||||
foreach my $i (@header) {
|
||||
my @lines = `grep compensated_function $i`;
|
||||
|
||||
foreach my $j (@lines) {
|
||||
if($j =~ /compensated_function[^\(]+ ([^\s\(]+)\s*\(/) {
|
||||
$h{$1}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open EXTRAS, "additional_checked_functions";
|
||||
|
||||
while (defined(my $line = <EXTRAS>)) {
|
||||
chomp $line;
|
||||
$line =~ s/\#.*$//g;
|
||||
$line =~ s/\s//g;
|
||||
if($line =~ /\S/) {
|
||||
$h{$line}++;
|
||||
}
|
||||
}
|
||||
|
||||
print "Found the following checked functions:\n";
|
||||
print "------------------------------------- \n";
|
||||
foreach my $i (sort keys %h) {
|
||||
print("$i\n");
|
||||
}
|
||||
print "\n";
|
||||
|
||||
|
||||
my $pwd = `pwd`;
|
||||
chomp $pwd;
|
||||
foreach my $i (@source) {
|
||||
chomp $i;
|
||||
open IN, $i;
|
||||
print "$i\n";
|
||||
# More accurate, but messes up line numbers. :(
|
||||
# open IN, "utilities/cpp_no_inc <$i |";
|
||||
$nest = 0;
|
||||
my $num = 0;
|
||||
while(my $line = <IN>) {
|
||||
$num++;
|
||||
my $in = 0;
|
||||
if ($line =~ /\bbegin_action(_ret)?\b/) {
|
||||
$nest++;
|
||||
$in = 1;
|
||||
}
|
||||
if ($line =~ /\bend_action(_ret)?\b/ || $line =~ /\bcompensate(_ret)?\b/) {
|
||||
$nest--;
|
||||
if($in) {
|
||||
warn "$pwd/$i:$num Cannot handle single line compensation checks\n";
|
||||
}
|
||||
}
|
||||
if($line !~ /\bcompensated_function\b/) {
|
||||
foreach my $j (keys %h) {
|
||||
if(($line =~ /$j\s*\(/) && !$nest) {
|
||||
warn "$pwd/$i:$num Unchecked invocation of $j\n";
|
||||
}
|
||||
}
|
||||
if ($nest < 0) {
|
||||
warn "$pwd/$i:$num Closed compensation check without open.\n";
|
||||
$nest = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nest > 0) {
|
||||
warn "$pwd/$i:$num Unclosed compensation check.\n";
|
||||
}
|
||||
close IN;
|
||||
|
||||
}
|
4
utilities/cpp_no_inc
Executable file
4
utilities/cpp_no_inc
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
grep -v \#include |cpp|grep -v '^\# [0-9]'
|
||||
|
||||
|
Loading…
Reference in a new issue