Update pgindent's typedefs blacklist, and make it easier to adjust.
authorTom Lane <[email protected]>
Tue, 27 Mar 2018 22:15:39 +0000 (18:15 -0400)
committerTom Lane <[email protected]>
Tue, 27 Mar 2018 22:15:39 +0000 (18:15 -0400)
It seems that all buildfarm members are now using the <stdbool.h> code
path, so that none of them report "bool" as a typedef.  We still need it
to be treated that way, so adjust pgindent to force that whether or not
it's in the given list.

Also, the recent introduction of LLVM infrastructure has caused the
appearance of some typedef names that we definitely *don't* want
treated as typedefs, such as "string" and "abs".  Extend the existing
blacklist to include these.  (Additions based on comparing v10's
typedefs list to what the buildfarm is currently emitting.)

Rearrange the code so that the lists of whitelisted/blacklisted
names are a bit easier to find and modify.

Andrew Dunstan and Tom Lane

Discussion: https://postgr.es/m/28690.1521912334@sss.pgh.pa.us

src/tools/pgindent/pgindent

index a32aaa64f339acddb5cee72752aa6c6c8adc4745..37dfccab6bd675f4c6ddda9bf2551528293ca361 100755 (executable)
@@ -50,6 +50,19 @@ $code_base ||= '.' unless @ARGV;
 $excludes ||= "$code_base/src/tools/pgindent/exclude_file_patterns"
   if $code_base && -f "$code_base/src/tools/pgindent/exclude_file_patterns";
 
+# The typedef list that's mechanically extracted by the buildfarm may omit
+# some names we want to treat like typedefs, e.g. "bool" (which is a macro
+# according to <stdbool.h>), and may include some names we don't want
+# treated as typedefs, although various headers that some builds include
+# might make them so.  For the moment we just hardwire a whitelist of names
+# to add and a blacklist of names to remove; eventually this may need to be
+# easier to configure.  Note that the typedefs need trailing newlines.
+my @whitelist = ("bool\n");
+
+my %blacklist = map { +"$_\n" => 1 }
+  qw( FD_SET date interval timestamp ANY
+      abs allocfunc iterator other pointer printfunc reference string type );
+
 # globals
 my @files;
 my $filtered_typedefs_fh;
@@ -118,9 +131,11 @@ sub load_typedefs
        }
    }
 
-   # remove certain entries
-   @typedefs =
-     grep { !m/^(FD_SET|date|interval|timestamp|ANY)\n?$/ } @typedefs;
+   # add whitelisted entries
+   push(@typedefs, @whitelist);
+
+   # remove blacklisted entries
+   @typedefs = grep { ! $blacklist{$_} } @typedefs;
 
    # write filtered typedefs
    my $filter_typedefs_fh = new File::Temp(TEMPLATE => "pgtypedefXXXXX");