From a3a88924926dbbb2266637650a9d6c86eb3d54a9 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sun, 21 Aug 2011 13:09:46 +0200 Subject: embed.pl was relying on embed.fnc starting with a pre-processor directive. Fix this subtle bug, and add comments. --- regen/embed.pl | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'regen/embed.pl') 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 { -- cgit v1.2.1