| 1 | #!/usr/bin/env perl | ||
| 2 | # bin/dev/group_refactor_names_map.pl - Annotate refactor names map with group comments | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | my ($infile, $outfile) = @ARGV; | ||
| 6 | die "Usage: $0 <input_map.pm> <output_grouped_map.pm>\n" unless $infile && $outfile; | ||
| 7 | open my $in, '<', $infile or die "Cannot open '$infile': $!"; | ||
| 8 | open my $out, '>', $outfile or die "Cannot write '$outfile': $!"; | ||
| 9 | my $suffix; | ||
| 10 | my $last_group = ''; | ||
| 11 | while (my $line = <$in>) { | ||
| 12 | # detect suffix section start | ||
| 13 | if ($line =~ /^\s*'([^']+)'\s*=>\s*{\s*$/) { | ||
| 14 | print $out $line; | ||
| 15 | $suffix = $1; | ||
| 16 | $last_group = ''; | ||
| 17 | my ($indent) = $line =~ /^(\s*)'/; | ||
| 18 | print $out $indent . "# ${suffix}_mappings: hot-name mappings for '$suffix' files\n"; | ||
| 19 | next; | ||
| 20 | } | ||
| 21 | # detect mapping line | ||
| 22 | if (defined $suffix && $line =~ /^(\s*)'([^']+)'\s*=>/) { | ||
| 23 | my ($indent, $key) = ($1, $2); | ||
| 24 | my $group_id; | ||
| 25 | my $desc; | ||
| 26 | if ($key =~ /^[A-Z]+?\d{2}$/) { # error codes | ||
| 27 | $group_id = "error_codes_${suffix}"; | ||
| 28 | $desc = "C++ error code constants"; | ||
| 29 | } elsif ($key =~ /^XS_pack_/) { | ||
| 30 | $group_id = "xs_pack_${suffix}"; | ||
| 31 | $desc = "XS 'pack' interface functions"; | ||
| 32 | } elsif ($key =~ /^XS_unpack_/) { | ||
| 33 | $group_id = "xs_unpack_${suffix}"; | ||
| 34 | $desc = "XS 'unpack' interface functions"; | ||
| 35 | } elsif ($key =~ /^_/) { | ||
| 36 | $group_id = "internal_${suffix}"; | ||
| 37 | $desc = "Internal naming pattern mappings"; | ||
| 38 | } elsif ($key =~ /^gsl_matrix_to_/) { | ||
| 39 | $group_id = "gsl_matrix_${suffix}"; | ||
| 40 | $desc = "GSL matrix conversion functions"; | ||
| 41 | } elsif ($key =~ /^input_/) { | ||
| 42 | $group_id = "input_${suffix}"; | ||
| 43 | $desc = "Input parameter naming mappings"; | ||
| 44 | } elsif ($key =~ /^integer_/) { | ||
| 45 | $group_id = "integer_${suffix}"; | ||
| 46 | $desc = "Integer type function mappings"; | ||
| 47 | } elsif ($key =~ /^number_/) { | ||
| 48 | $group_id = "number_${suffix}"; | ||
| 49 | $desc = "Number type function mappings"; | ||
| 50 | } elsif ($key =~ /^object_/) { | ||
| 51 | $group_id = "object_${suffix}"; | ||
| 52 | $desc = "Object type function mappings"; | ||
| 53 | } elsif ($key =~ /^scalar/) { | ||
| 54 | $group_id = "scalar_${suffix}"; | ||
| 55 | $desc = "Scalar type function mappings"; | ||
| 56 | } elsif ($key =~ /^string_/) { | ||
| 57 | $group_id = "string_${suffix}"; | ||
| 58 | $desc = "String type function mappings"; | ||
| 59 | } elsif ($key =~ /_CHECK/) { | ||
| 60 | $group_id = "check_${suffix}"; | ||
| 61 | $desc = "Type-checking functions"; | ||
| 62 | } elsif ($key =~ /_to_string/) { | ||
| 63 | $group_id = "to_string_${suffix}"; | ||
| 64 | $desc = "to_string functions"; | ||
| 65 | } elsif ($key =~ /_typetest/) { | ||
| 66 | $group_id = "typetest_${suffix}"; | ||
| 67 | $desc = "Type-testing functions"; | ||
| 68 | } else { | ||
| 69 | $group_id = "other_${suffix}"; | ||
| 70 | $desc = "Miscellaneous hot name mappings"; | ||
| 71 | } | ||
| 72 | if ($group_id ne $last_group) { | ||
| 73 | print $out $indent . "# $group_id: $desc\n"; | ||
| 74 | $last_group = $group_id; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | print $out $line; | ||
| 78 | } | ||
| 79 | close $in; | ||
| 80 | close $out; | ||
| 81 | exit 0; |