App-UnifdefPlus
view release on metacpan or search on metacpan
lib/UnifdefPlus.pm view on Meta::CPAN
}
else {
$self->parseIf( $litExpr, $expression, $keep, 0 );
}
}
elsif ( $line =~ /$EXPR->{$lang}->{IFEQ}/s ) {
# expression is assumed to be makefile here...
$litExpr = $1;
$expression = $2;
my $comment;
# TBD: preserve eol expressions in simplified expression...
my ($simplifiedExpr, $rss, $match) = $self->makefileCompareExprs($2);
my $wasSimplified = $rss==RSS_UNCHANGED?0:1;
$simplifiedExpr = $TRUE_RESOLVED if ($rss == RSS_RESOLVED && $match == MATCH_RESOLVED);
$simplifiedExpr = $FALSE_RESOLVED if ($rss == RSS_RESOLVED && $match == NO_MATCH_RESOLVED);
$self->parseIf( $litExpr, $simplifiedExpr, $keep, $wasSimplified );
}
elsif ( $line =~ /$EXPR->{$lang}->{IFNEQ}/s ) {
# expression is assumed to be makefile here...
$litExpr = $1;
$expression = $2;
my $comment;
# TBD: preserve eol expressions in simplified expression...
my ($simplifiedExpr, $rss, $match) = $self->makefileCompareExprs($2);
my $wasSimplified = $rss!=RSS_UNCHANGED;
$simplifiedExpr = $FALSE_RESOLVED if ($rss == RSS_RESOLVED && $match == MATCH_RESOLVED);
$simplifiedExpr = $TRUE_RESOLVED if ($rss == RSS_RESOLVED && $match == NO_MATCH_RESOLVED);
$self->parseIf( $litExpr, $simplifiedExpr, $keep, $wasSimplified );
}
elsif ( $line =~ /$EXPR->{$lang}->{IF}/s ) {
$litExpr = $1;
my $wasSimplified;
($expression, $wasSimplified) = $self->parseCondition($2);
lib/UnifdefPlus.pm view on Meta::CPAN
my $self = shift;
my $origExprsStr = shift;
my ($openBrace, $closeBrace, $comma) = ("","",""); #includes whitespace
my ($expr1Quote, $expr2Quote, $ws) = ("","","");
my ($expr1,$expr2);
my $remainder;
my $rss;
my $simplifiedStr ="";
my $exprsStr;
my $match = MATCH_UNKNOWN;
my $eolComment;
if ( $origExprsStr =~ /^\(/ ) {
($exprsStr,$eolComment) = extract_bracketed($origExprsStr, '(")');
$exprsStr =~ s/^\(|\)$//g;
($expr1,$expr2) = getParameterList($exprsStr);
# trim expressions, and store whitespace:
$expr1 =~ s/^(\s*)|(\s*)$//g;
my ($ws1,$ws2) = ($1 || "",$2 || "");
$expr2 =~ s/^(\s*)|(\s*)$//g;
my ($ws3,$ws4) = ($1 || "",$2 || "");
$openBrace = '('.$ws1;
$comma = "".$ws2.",".$ws3;
$closeBrace = "".$ws4.')';
} else {
# we have two space delimitted quoted strings..
($expr1, $remainder) = extract_delimited($origExprsStr,q{'"});
return if ( ! defined $expr1 );
#tbd: figure out how to do the following two lines in one...
$remainder =~ s/^(\s++)//;
$ws = $1;
($expr2, $remainder) = extract_delimited($remainder,q{'"});
$eolComment = $remainder;
($expr1Quote) = $expr1 =~ /^(["'])/;
($expr2Quote) = $expr2 =~ /^(["'])/;
$expr1 =~ s/^(["'])|["']$//g;
$expr2 =~ s/^(["'])|["']$//g;
}
die if ((! defined $expr1) || (! defined $expr2) );
# at this point we have expr1 and expr2 which are the expressions, without quotes/braces/commas.
# if openBrace/closeBrace are set, original expression was braced. Otherwise expr1Quote
# quote will be set.
lib/UnifdefPlus.pm view on Meta::CPAN
# and check if expression1 =~ regex...
#test if both start with constant, and if those are equal.
my ($p1) = $se1 =~ /^([^\$]*)/;
my ($p2) = $se2 =~ /^([^\$]*)/;
($p1,$p2) = ($p2,$p1) if (length $p1 > length $p2);
$match = NO_MATCH_RESOLVED if ($p2 !~ /^$p1/);
#tbd: add test for end of string if end of string is constant
#tbd: add test for middle of string if one term is constant and other is not.
}
$simplifiedStr = $openBrace.$se1.$comma.$se2.$closeBrace.$eolComment
if $openBrace;
$simplifiedStr = $openBrace.$expr1Quote.$se1.$expr1Quote.$ws.$expr2Quote.$se2.$expr2Quote.$eolComment
if $expr1Quote;
return ($simplifiedStr,$rss,$match);
}
#TBD: simplfiy obj-$(x) statements for kbuild makefiles...
## --------------------------------------------------------------------------
lib/UnifdefPlus.pm view on Meta::CPAN
#do not echo
}
else {
$condition =~ s/$LINE_SEP/\\\n/g;
push(@$outLinesRef, $tmp . $condition . "\n");
}
}
elsif ($line =~ /^(\s+(?:[^"]|(?:"(?:[^"\\]|\\.)*"))+)(\s+if\s+)(.*?)(\s*\#.*)?$/) {
my $term = $1;
my $ifTerm = $2;
my $eolComment = defined($4) ? $4 : "";
print DBGOUT " conditional statement: $3" if ($self->{dbg});
my ($condition,$result) = $self->kconfigSimplifyExprTop($3);
if ($result eq $N) {
}
elsif ($result eq $Y || $result eq $M) {
$term =~ s/$LINE_SEP/\\\n/g;
$eolComment =~ s/$LINE_SEP/\\\n/g;
push(@$outLinesRef, $term . $eolComment . "\n");
}
else {
$term =~ s/$LINE_SEP/\\\n/g;
$ifTerm =~ s/$LINE_SEP/\\\n/g;
$condition =~ s/$LINE_SEP/\\\n/g;
$eolComment =~ s/$LINE_SEP/\\\n/g;
push(@$outLinesRef, $term . $ifTerm . $condition . $eolComment ."\n");
}
}
elsif ($line =~ /^\s+(\w+)\s*(.*)$/) {
$line =~ s/$LINE_SEP/\\\n/g;
print DBGOUT " + - $line...\n" if ($self->{dbg});
push(@$outLinesRef, $line."\n");
}
else {
$self->{error} = "Error parsing Kconfig file ($line)";
print STDERR "".$self->{error}."\n" if($showErrs);
lib/UnifdefPlus.pm view on Meta::CPAN
my $endStr = "";
$endStr = qw/endchoice/ if ($line =~ /^choice\s*$/);
$endStr = qw/endmenu/ if ($line =~ /^menu\s/);
$endStr = qw/endif/ if ($line =~ /^if\s/);
if ($endStr) {
$hideEndif = 0;
#special handling for if: we need to modify the condition
if ($line =~ /^if\s+(.*?)(\s*(?:\#.*$))?$/) {
my ($condition, $result, $eolComment) = ($self->kconfigSimplifyExprTop($1), $2);
$eolComment = "" if !defined($eolComment);
if ($condition ne $1) {
# expression changed -- rewriting
if ($result eq $N) {
$isVisible = 0 ;
$self->{wasModified} = 1;
} elsif ($result eq $Y || $result eq $M) {
#pop off if statement (if statement may be multiline...)
#print STDERR "condition: ".$condition." Y:".$Y."\n";
while (! (pop(@$outLinesRef) =~ /^if\s/) ) {};
$self->{wasModified} = 1;
$hideEndif = 1 ;
} else {
#pop off if statement (if statement may be multiline...)
while (! (pop(@$outLinesRef) =~ /^if\s/) ) {};
push(@$outLinesRef, "if ".$condition.$eolComment."\n");
}
}
}
#read block:
while(1) {
my @subEntryOutLines = ();
last if (scalar(@{$self->{inlines}}) <= 0);
my $isNextEntryVisible = $self->kconfigReadNextEntry(\@subEntryOutLines);
if ($isNextEntryVisible != 0) {
#if (defined(D1) || defined(D2)) && defined(U1) || defined(FOOBAR)
/* 4.6 #if (defined(D1) || defined(D2)) && defined(U1) || defined(FOOBAR) (V) */
#else
/* 4.6 #else */
#endif
#if (D2 * 2 - 1 > D1 + 1 ) \
&& (defined(FOO) || defined(FOOBAR)) \
&& (FOOBAR > 3 * (9 - 2) ) // eol comment
/* 4.20 complex... -- should resolve to #if ( FOOBAR > 3 * (9 - 2) ) // eol comment */
#else
/* 4.20 #else */
#endif
#if ( defined(U1) && defined(UNKNOWN1) ) || \
!defined D1 // resolves to false
/* 4.21 line will NOT appear */
#elif D1 <= 3 && U1 > (3 + 2) // (4.21 condition simplifies)
/* 4.21 line will appear */
#elif D1 > 3 // condition resolves to false (1 < 3...)
t/test1.c.expectedout view on Meta::CPAN
/* 4.5 #else (#if (defined(D1) || defined(D2)) && defined(U1)) (V)*/
#if defined(FOOBAR)
/* 4.6 #if (defined(D1) || defined(D2)) && defined(U1) || defined(FOOBAR) (V) */
#else
/* 4.6 #else */
#endif
#if (FOOBAR > 3 * (9 - 2) ) // eol comment
/* 4.20 complex... -- should resolve to #if ( FOOBAR > 3 * (9 - 2) ) // eol comment */
#else
/* 4.20 #else */
#endif
#if U1 > (3 + 2) // (4.21 condition simplifies)
/* 4.21 line will appear */
#else
/* 4.21 line will appear, as an else to the unknown */
#endif
t/test1.c.out view on Meta::CPAN
/* 4.5 #else (#if (defined(D1) || defined(D2)) && defined(U1)) (V)*/
#if defined(FOOBAR)
/* 4.6 #if (defined(D1) || defined(D2)) && defined(U1) || defined(FOOBAR) (V) */
#else
/* 4.6 #else */
#endif
#if (FOOBAR > 3 * (9 - 2) ) // eol comment
/* 4.20 complex... -- should resolve to #if ( FOOBAR > 3 * (9 - 2) ) // eol comment */
#else
/* 4.20 #else */
#endif
#if U1 > (3 + 2) // (4.21 condition simplifies)
/* 4.21 line will appear */
#else
/* 4.21 line will appear, as an else to the unknown */
#endif
( run in 0.893 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )