This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/mk_invlists.pl: Suppress empty enum declarations
authorKarl Williamson <khw@cpan.org>
Fri, 23 Mar 2018 18:11:48 +0000 (12:11 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 26 Mar 2018 22:26:54 +0000 (16:26 -0600)
This diverts the outputting of the enum typedefs until after they are
fully known, so that an empty one can be suppressed.

A future commit will need this

charclass_invlists.h
regen/mk_invlists.pl

index 80cb33b..9ffcb91 100644 (file)
@@ -109391,5 +109391,5 @@ static const U8 WB_table[24][24] = {
  * ea4dc61a00d2db9bd46f3ddec706b5b7b11e8fcf848fb384b54b507fb70d8e90 lib/unicore/mktables
  * 21653d2744fdd071f9ef138c805393901bb9547cf3e777ebf50215a191f986ea lib/unicore/version
  * 913d2f93f3cb6cdf1664db888bf840bc4eb074eef824e082fceda24a9445e60c regen/charset_translations.pl
- * fed85f75545bcdcf538d9c83e91c5deb29c329db90bad66f56909e0708aa1f20 regen/mk_invlists.pl
+ * 9c77f23b9db5b72797a55775a88862159d7a91d5dcf28b9aa2dcd38e5a9cecf5 regen/mk_invlists.pl
  * ex: set ro: */
index cf91711..e56028e 100644 (file)
@@ -375,28 +375,17 @@ sub output_invmap ($$$$$$$) {
                                       || substr($short_name, 0, 1) =~ /[[:lower:]]/;
         $name_prefix = "${short_name}_";
 
-        # Currently unneeded
-        #print $out_fh "\n#define ${name_prefix}ENUM_COUNT ", scalar keys %enums, "\n";
-
-        if ($input_format eq 'sl') {
-            print $out_fh
-            "\n/* Negative enum values indicate the need to use an auxiliary"
-          . " table\n * consisting of the list of enums this one expands to."
-          . "  The absolute\n * values of the negative enums are indices into"
-          . " a table of the auxiliary\n * tables' addresses */";
-        }
-
         # Start the enum definition for this map
-        print $out_fh "\ntypedef enum {\n";
+        my @enum_definition;
         my @enum_list;
         foreach my $enum (keys %enums) {
             $enum_list[$enums{$enum}] = $enum;
         }
         foreach my $i (0 .. @enum_list - 1) {
-            print $out_fh  ",\n" if $i > 0;
+            push @enum_definition, ",\n" if $i > 0;
 
             my $name = $enum_list[$i];
-            print $out_fh  "\t${name_prefix}$name = $i";
+            push @enum_definition, "\t${name_prefix}$name = $i";
         }
 
         # For an 'sl' property, we need extra enums, because some of the
@@ -431,15 +420,37 @@ sub output_invmap ($$$$$$$) {
 
                 # And add to the enum values
                 if (! $already_found) {
-                    print $out_fh  ",\n\t${name_prefix}$element = -$i";
+                    push @enum_definition, ",\n\t${name_prefix}$element = -$i";
                 }
             }
         }
 
-        print $out_fh "\n";
         $declaration_type = "${name_prefix}enum";
-        print $out_fh "} $declaration_type;\n";
-        # Finished with the enum defintion.
+
+        # Finished with the enum definition.  If it only contains one element,
+        # that is a dummy, default one
+        if (scalar @enum_definition > 1) {
+
+            # Currently unneeded
+            #print $out_fh "\n#define ${name_prefix}ENUM_COUNT ",
+            #                                   ..scalar keys %enums, "\n";
+
+            if ($input_format =~ /l/) {
+                print $out_fh
+                "\n",
+                "/* Negative enum values indicate the need to use an",
+                    " auxiliary table\n",
+                " * consisting of the list of enums this one expands to.",
+                    "  The absolute\n",
+                " * values of the negative enums are indices into a table",
+                    " of the auxiliary\n",
+                " * tables' addresses */";
+            }
+            print $out_fh "\ntypedef enum {\n";
+            print $out_fh join "", @enum_definition;
+            print $out_fh "\n";
+            print $out_fh "} $declaration_type;\n";
+        }
 
         switch_pound_if($name, $where) if $is_public_enum;