From f68e6b9dd349d8030febe640f774ce2cda084a41 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Wed, 16 Feb 2005 02:11:01 +0000 Subject: [PATCH] Heuristic perl script to check for proper use of compensations. --- utilities/check_compensations | 80 +++++++++++++++++++++++++++++++++++ utilities/cpp_no_inc | 4 ++ 2 files changed, 84 insertions(+) create mode 100755 utilities/check_compensations create mode 100755 utilities/cpp_no_inc diff --git a/utilities/check_compensations b/utilities/check_compensations new file mode 100755 index 0000000..0019807 --- /dev/null +++ b/utilities/check_compensations @@ -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 = )) { + 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 = ) { + $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; + +} diff --git a/utilities/cpp_no_inc b/utilities/cpp_no_inc new file mode 100755 index 0000000..ff6660c --- /dev/null +++ b/utilities/cpp_no_inc @@ -0,0 +1,4 @@ +#!/bin/bash +grep -v \#include |cpp|grep -v '^\# [0-9]' + +