Optimizations in process_compiler_directive()

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2012-12-22 08:14:46 -08:00
parent 96b61ea05c
commit bc230c00a3

View File

@ -2095,6 +2095,8 @@ sub process_compiler_directive( $$$$ ) {
my ($keyword, $expression) = ( uc $1, $2 );
$keyword =~ s/\s*$//;
if ( supplied $expression ) {
$expression =~ s/#.*//;
$expression =~ s/\s*$//;
@ -2104,12 +2106,14 @@ sub process_compiler_directive( $$$$ ) {
my ( $lastkeyword, $prioromit, $included, $lastlinenumber ) = @ifstack ? @{$ifstack[-1]} : ('', 0, 0, 0 );
if ( $keyword =~ /^IF/ ) {
my %directives = ( IF => sub() {
directive_error( "Missing IF expression" , $filename, $linenumber ) unless supplied $expression;
my $nextomitting = $omitting || ! evaluate_expression( $expression , $filename, $linenumber );
push @ifstack, [ 'IF', $omitting, ! $nextomitting, $linenumber ];
$omitting = $nextomitting;
} elsif ( $keyword =~ /^ELSIF/ ) {
} ,
ELSIF => sub() {
directive_error( "?ELSIF has no matching ?IF" , $filename, $linenumber ) unless @ifstack > $ifstack && $lastkeyword =~ /IF/;
directive_error( "Missing IF expression" , $filename, $linenumber ) unless $expression;
if ( $omitting && ! $included ) {
@ -2125,18 +2129,24 @@ sub process_compiler_directive( $$$$ ) {
$omitting = 1;
}
$ifstack[-1] = [ 'ELSIF', $prioromit, $included, $lastlinenumber ];
} elsif ( $keyword eq 'ELSE' ) {
} ,
ELSE => sub() {
directive_error( "Invalid ?ELSE" , $filename, $linenumber ) unless $expression eq '';
directive_error( "?ELSE has no matching ?IF" , $filename, $linenumber ) unless @ifstack > $ifstack && $lastkeyword =~ /IF/;
$omitting = $included || ! $omitting unless $prioromit;
$ifstack[-1] = [ 'ELSE', $prioromit, 1, $lastlinenumber ];
} elsif ( $keyword eq 'ENDIF' ) {
} ,
ENDIF => sub() {
directive_error( "Invalid ?ENDIF" , $filename, $linenumber ) unless $expression eq '';
directive_error( q(Unexpected "?ENDIF" without matching ?IF or ?ELSE) , $filename, $linenumber ) if @ifstack <= $ifstack;
$omitting = $prioromit;
pop @ifstack;
} elsif ( ! $omitting ) {
if ( $keyword =~ /^SET/ ) {
} ,
SET => sub() {
if ( ! $omitting ) {
directive_error( "Missing SET variable", $filename, $linenumber ) unless supplied $expression;
( my $var , $expression ) = split ' ', $expression, 2;
directive_error( "Invalid SET variable ($var)", $filename, $linenumber) unless $var =~ /^\$?([a-zA-Z]\w*)$/;
@ -2144,12 +2154,20 @@ sub process_compiler_directive( $$$$ ) {
$variables{$1} = evaluate_expression( $expression,
$filename,
$linenumber );
} elsif ( $keyword =~ /^FORMAT/ ) {
}
} ,
FORMAT => sub() {
if ( ! $omitting ) {
directive_error( "Missing format", $filename, $linenumber ) unless supplied $expression;
directive_error( "Invalid format ($expression)", $filename, $linenumber ) unless $expression =~ /^\d+$/;
directive_error( "Format must be between 1 and $max_format", $filename, $linenumber ) unless $expression && $expression <= $max_format;
$file_format = $expression;
} else {
}
} ,
RESET => sub() {
if ( ! $omitting ) {
my $var = $expression;
directive_error( "Missing RESET variable", $filename, $linenumber) unless supplied $var;
directive_error( "Invalid RESET variable ($var)", $filename, $linenumber) unless $var =~ /^\$?([a-zA-Z]\w*)$/;
@ -2161,6 +2179,13 @@ sub process_compiler_directive( $$$$ ) {
}
}
}
);
if ( my $function = $directives{$keyword} ) {
$function->();
} else {
assert( 0, $keyword );
}
$omitting;
}