checkapi.prl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #
  2. # Released to public domain by Donald Anderson  dda@world.std.com
  3. # No warranties.
  4. #
  5. # Perl script to check for matching of JNI interfaces to implementation.
  6. # We check all .cpp arguments and .h arguments and make sure that for
  7. # each .h declaration (marked by JNIEXPORT keyword), there is a .cpp
  8. # definition for the same function (also marked by JNIEXPORT keyword),
  9. # and vice versa.  Definitions and declarations are determined solely
  10. # by whether they are in a .h or .cpp file - we don't do any further
  11. # analysis.
  12. #
  13. # Some additions made to help with Berkeley DB sources:
  14. #
  15. #   Berkeley DB Java sources use JAVADB_*_ACCESS #defines
  16. #   to quickly define routine access functions.
  17. foreach $file (<@ARGV>) {      # glob allows direct use from Win* makefiles
  18.     open (FILE, $file) || die "$file: cannot openn";
  19.     $dot_h = 0;
  20.     if ($file =~ /.*[hH]$/) {
  21.         $dot_h = 1;
  22.     }
  23.     $in_def = 0;
  24. nextline:
  25.     while (<FILE>) {
  26.         chop;
  27.         if (/JNIEXPORT/ || /^JAVADB_.*_ACCESS/) {
  28.             $in_def = 1;
  29.             $def = "";
  30.         }
  31.         if ($in_def == 1) {
  32.             $def .= $_;
  33.         }
  34.         if (/)/) {
  35.             $line = "";
  36.             $in_def = 0;
  37.             if ($def eq "") {
  38.                 next nextline;
  39.             }
  40.             $_ = $def;
  41.             # remove comments
  42.             s@/*[^*]**/@@g;
  43.             s@[  ][  ]*@ @g;
  44.             s@JNIEnv ** *@JNIEnv @g;
  45.             s@([,*()]) @1@g;
  46.             s@ ([,*()])@1@g;
  47.             s/JAVADB_WO_ACCESS_METHOD/JAVADB_WO_ACCESS/;
  48.             if (/^JAVADB_.*_ACCESS/) {
  49.                 s@  *@ @g;
  50.                 s@_ACCESS_STRING(([^,]*),@_ACCESS(1,jstring,@;
  51.                 s@_ACCESS_BEFORE_APPINIT@_ACCESS@;
  52.                 s@_ACCESS(@,normal,@;
  53.                 s@JAVADB_@@;
  54.                 s@)@,@;
  55.                 @vars = split(/,/);
  56.                 $get = 0;
  57.                 $set = 0;
  58.                 if (@vars[0] eq "RW") {
  59.                     $get = 1;
  60.                     $set = 1;
  61.                 }
  62.                 if (@vars[0] eq "RO") {
  63.                     $get = 1;
  64.                 }
  65.                 if (@vars[0] eq "WO") {
  66.                     $set = 1;
  67.                 }
  68.                 if ($get == 0 && $set == 0) {
  69.                     print "Invalid use of JAVADB_ macron";
  70.                 }
  71.                 if ($set == 1) {
  72.                     $line = "JNIEXPORT void JNICALL Java_com_sleepycat_db_@vars[2]_set_1@vars[4](JNIEnv,jobject,@vars[3])";
  73.                 }
  74.                 if ($get == 1) {
  75.                     $line2 = "JNIEXPORT @vars[3] JNICALL Java_com_sleepycat_db_@vars[2]_get_1@vars[4](JNIEnv,jobject)";
  76.                 }
  77.             }
  78.             else {
  79.                 s@([,(][a-zA-Z0-9_]*) [a-zA-Z0-9_]*@1@g;
  80.                 s@;$@@g;
  81.                 $line = $_;
  82.             }
  83.             $def = "";
  84.             if ($line ne "") {
  85.                 if ($lines{$line} eq "") {
  86.                     $lines{$line} = 0;
  87.                 }
  88.                 if ($dot_h == 1) {
  89.                     $lines{$line} += 1;
  90.                 }
  91.                 else {
  92.                     $lines{$line} -= 1;
  93.                 }
  94.                 $line = "";
  95.             }
  96.             if ($line2 ne "") {
  97.                 if ($lines{$line2} eq "") {
  98.                     $lines{$line2} = 0;
  99.                 }
  100.                 if ($dot_h == 1) {
  101.                     $lines{$line2} += 1;
  102.                 }
  103.                 else {
  104.                     $lines{$line2} -= 1;
  105.                 }
  106.                 $line2 = "";
  107.             }
  108.         }
  109.     }
  110.     close (FILE);
  111. }
  112. $status = 0;
  113. foreach $key (sort keys %lines) {
  114.     if ($lines{$key} != 0) {
  115.         if ($lines{$key} > 0) {
  116.             print "Missing .cpp implementation: $lines${key}n";
  117.             $status = 1;
  118.         }
  119.         else {
  120.             print "Missing .h declaration: $lines${key}n";
  121.             $status = 1;
  122.         }
  123.     }
  124. }
  125. exit ($status);