App-UnifdefPlus

 view release on metacpan or  search on metacpan

lib/UnifdefPlus.pm  view on Meta::CPAN

my $RESOLVED_PREFIX_PTRN = qr/$RESOLVED_PREFIX/;
my $TRUE_RESOLVED_PTRN =  qr/\b(?:$RESOLVED_PREFIX)[1-9][0-9]*\b/;
my $FALSE_RESOLVED_PTRN = qr/\b(?:$RESOLVED_PREFIX)0\b/;
my $TRUE_SIMPLIFIED_PTRN =  qr/\b(?:$SIMPLIFIED_PREFIX)[0-9][1-9]*\b/;
my $FALSE_SIMPLIFIED_PTRN = qr/\b(?:$SIMPLIFIED_PREFIX)0\b/;

my $TRUE_PTRN =  qr/(?:\b(?:$SIMPLIFIED_PREFIX|$RESOLVED_PREFIX)?[1-9][0-9]*|0x[1-9][0-9]*|TRUE)\b/;
my $FALSE_PTRN = qr/(?:\b(?:$SIMPLIFIED_PREFIX|$RESOLVED_PREFIX|)0|0x0|NULL|FALSE)\b/;


sub getValue($) {
    my $string = shift;
    return $1 if ($string =~ /^(?:$RESOLVED_PREFIX|$SIMPLIFIED_PREFIX)(\d+)$/);
    return $string if ($string =~ /^([1-9][0-9]*)$/);        
    return $string if ($string =~ /^0$/);        
    return hex $string if ($string =~ /^0x[0-9A-Fa-f]+$/);
    return oct $string if ($string =~ /^0[0-9]*$/);
    return 1 if ($string eq "TRUE");
    return 0 if ($string eq "FALSE");
    return "unknown";
}

sub isNumber_($) {
    my $string = shift;
    return getValue($string) ne "unknown";
}

sub trim($) {
    my $string = shift;
    $string =~ s/^\s+//;
    $string =~ s/\s+$//;
    return $string;
}

sub trimWs($) {
    my $string = shift;
    #my ($ws1, $ws2);
    $string =~ /^(\s*)(\S*(?:\s+\S+)*)(\s*)$/;
    return ($1,$2,$3);
}

#from: http://www.perlmonks.org/?node_id=406883
sub max {
    my ($m, @vars) = @_;
    for (@vars) {

lib/UnifdefPlus.pm  view on Meta::CPAN


}

# makefileSimplifyIf($ifStmt, $condition)
# 		ifStmnt is one of : ifeq, ifneq, ifdef, ifndef (plus trailing whitespace)
# 		condition is the text following that.
#
# returns: ($ifStmnt, $simplifiedCond, $rss)
#     simplifiedCond is $RESOLVED_TRUE, $RESOLVED_FALSE, or the simplified expression
#		
sub makefileSimplifyIf() 
{
	my $self = shift;
	my $ifStmt = shift;
	my $condition = shift;
    my $lang = $self->{lang};
    my $rss = RSS_UNCHANGED;
    
  
	if($ifStmt =~ /^$EXPR->{$lang}->{IFDEF}|^$EXPR->{$lang}->{IFNDEF}/) {
		#TBD: simplify expression?

lib/UnifdefPlus.pm  view on Meta::CPAN

#         "expr1" 'expr2'   #optional comments
#         'expr1' "expr2"   #optional comments
#         ( expr1 , expr2 ) #optional comments
#     where whitespace around the comma and parens are ignored in the last case.
#     neg is negate -- if this is set return opposite
# returns: ($simplifiedexpr, $rss, $match)
#	  where $match is one of:
#           MATCH_RESOLVED - if expressions were resolved and match
#           NO_MATCH_RESOLVED - if experssions were resolved and can not match
#           MATCH_UNKNOWN -  otherwise.
sub makefileCompareExprs() {
	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;



( run in 0.628 second using v1.01-cache-2.11-cpan-65fba6d93b7 )