summaryrefslogtreecommitdiff
path: root/regen/embed.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-08-21 13:09:46 +0200
committerNicholas Clark <nick@ccl4.org>2011-08-25 11:34:36 +0200
commita3a88924926dbbb2266637650a9d6c86eb3d54a9 (patch)
tree60047771121e79236d37ec06b0e96971a0cb9287 /regen/embed.pl
parentdcd8b78a7db42cd98ee5f1e4d4a9dea223e29989 (diff)
downloadperl-a3a88924926dbbb2266637650a9d6c86eb3d54a9.tar.gz
embed.pl was relying on embed.fnc starting with a pre-processor directive.
Fix this subtle bug, and add comments.
Diffstat (limited to 'regen/embed.pl')
-rwxr-xr-xregen/embed.pl36
1 files changed, 24 insertions, 12 deletions
diff --git a/regen/embed.pl b/regen/embed.pl
index 71422bbaa8..5be37445e6 100755
--- a/regen/embed.pl
+++ b/regen/embed.pl
@@ -106,9 +106,31 @@ my (@core, @ext, @api);
{
# Cluster entries in embed.fnc that have the same #ifdef guards.
# Also, split out at the top level the three classes of functions.
+ # Output structure is actually the same as input structure - an
+ # (ordered) list of array references, where the elements in the reference
+ # determine what it is - a reference to a 1-element array is a
+ # pre-processor directive, a reference to 2+ element array is a function.
+
+ # Records the current pre-processor state:
my @state;
+ # Nested structure to group functions by the pre-processor conditions that
+ # control when they are compiled:
my %groups;
- my $current;
+
+ sub current_group {
+ my $group = \%groups;
+ # Nested #if blocks are effectively &&ed together
+ # For embed.fnc, ordering within the && isn't relevant, so we can
+ # sort them to try to group more functions together.
+ foreach (sort @state) {
+ $group->{$_} ||= {};
+ $group = $group->{$_};
+ }
+ return $group->{''} ||= [];
+ }
+
+ my $current = current_group();
+
foreach (@embed) {
if (@$_ > 1) {
push @$current, $_;
@@ -129,17 +151,7 @@ my (@core, @ext, @api);
} else {
die "Unhandled pre-processor directive '$_->[0]' in embed.fnc";
}
- $current = \%groups;
- # Nested #if blocks are effectively &&ed together
- # For embed.fnc, ordering withing the && isn't relevant, so we can
- # sort them to try to group more functions together.
- my @sorted = sort @state;
- while (my $directive = shift @sorted) {
- $current->{$directive} ||= {};
- $current = $current->{$directive};
- }
- $current->{''} ||= [];
- $current = $current->{''};
+ $current = current_group();
}
sub add_level {