diff options
author | Karl Williamson <khw@cpan.org> | 2016-01-15 22:20:30 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2016-01-19 15:08:59 -0700 |
commit | 6dc808648618929bd0388e2c65377210e6044fd8 (patch) | |
tree | 1c5a1f5f6549d62d212137ad03fd8449db900658 /regen | |
parent | 3c84a230ed64f5ef68617ef355b5b35bf93a3951 (diff) | |
download | perl-6dc808648618929bd0388e2c65377210e6044fd8.tar.gz |
regen/mk_invlists.pl: Keep internal enum values last
Most Unicode properties have a finite set of possible values. Most, for
example, are binary, they can be either true or false, but nothing in
between. Others have more possibilities (and still others, like Name,
are not restricted at all. The Word Break property, for example can
take on a restricted set of values, currently 19 in all, that indicate
what type, for purposes of word breaking, the character is.
In implementing things like Word Break, Perl adds some internal-only
values, like EDGE, which means matching like /^/ or /$/. By using
these synthetic values, we don't need to have extra code for edge
cases.
These properties are implemented using C enums. Prior to this commit,
the actual numeric values for each enum was mostly arbitrary, with the
synthetic ones intermixed with the offical ones. This commit changes
that so the synthetic ones are all higher numbers than any official ones,
and the order they appear in the generating code will be the numerical
order they have, so that the program has control of their order.
Diffstat (limited to 'regen')
-rw-r--r-- | regen/mk_invlists.pl | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/regen/mk_invlists.pl b/regen/mk_invlists.pl index 3f2cfc3521..3a4101f25b 100644 --- a/regen/mk_invlists.pl +++ b/regen/mk_invlists.pl @@ -261,9 +261,11 @@ sub output_invmap ($$$$$$$) { push @enums, @expected_enums; # Add in the extra values coded into this program, and sort. - push @enums, split /,/, $extra_enums if $extra_enums ne ""; @enums = sort @enums; + # The internal enums comes last. + push @enums, split /,/, $extra_enums if $extra_enums ne ""; + # Assign a value to each element of the enum. The default # value always gets 0; the others are arbitrarily assigned. my $enum_val = 0; @@ -288,12 +290,15 @@ sub output_invmap ($$$$$$$) { print $out_fh "\n#define ${name_prefix}ENUM_COUNT ", scalar keys %enums, "\n"; print $out_fh "\ntypedef enum {\n"; - print $out_fh "\t${name_prefix}$default = $enums{$default},\n"; - delete $enums{$default}; - foreach my $enum (sort { $a cmp $b } keys %enums) { - print $out_fh "\t${name_prefix}$enum = $enums{$enum}"; - print $out_fh "," if $enums{$enum} < $enum_count - 1; - print $out_fh "\n"; + my @enum_list; + foreach my $enum (keys %enums) { + $enum_list[$enums{$enum}] = $enum; + } + foreach my $i (0 .. @enum_list - 1) { + my $name = $enum_list[$i]; + print $out_fh "\t${name_prefix}$name = $i"; + print $out_fh "," if $i < $enum_count - 1; + print $out_fh "\n"; } $declaration_type = "${name_prefix}enum"; print $out_fh "} $declaration_type;\n"; |