diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-12-13 16:14:28 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-12-13 16:14:28 +0000 |
commit | dcbc845fb891a1d10476408f6e6cd517389f8dab (patch) | |
tree | a61a7e1fb5c4909436ac77a56a4738214b921b54 /lib/sbin | |
parent | bb5c5e16ac3d16da3ddd5e79051ae601d566f4eb (diff) |
Warn if there are empty macro arguments. That is, given
#define M2(a,b)
warn about the uses M2(x,) or M2(,y) or M2(,).
The empty arguments are still handled correctly. These warnings are only to
make it easier to port to systems where the system cpp does not handle empty
arguments and where one does not want to use the perl cpp instead.
Patch from Erik Schnetter.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4213 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin')
-rwxr-xr-x | lib/sbin/cpp.pl | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/sbin/cpp.pl b/lib/sbin/cpp.pl index 0016fdff..a7c62f38 100755 --- a/lib/sbin/cpp.pl +++ b/lib/sbin/cpp.pl @@ -43,9 +43,15 @@ $current_wd = "."; # Are we in the middle of a comment ? $incomment = 0; +# Number of non-fatal errors encountered +$errorcount = 0; + ############################################################################### ############################################################################### +my $empty_args_warning = 1; +my $empty_args_error = 0; + # Parse the command line ($source_file, $output_file, $do_deps, @include_path) = &ParseCommandLine(@ARGV); @@ -112,6 +118,13 @@ if($do_deps) } } +if ($errorcount > 0) +{ + # There were non-fatal errors + exit 1; +} + +# There were no errors exit; ############################################################################### @@ -804,7 +817,7 @@ sub ExpandMacro my ($macro, $args, $filename, $linenumber) = @_; my $retcode = 0; - my @arguments = &SplitArgs($args); + my @arguments; # SplitArgs returns one (empty) argument for macros without arguments, # because it cannot distinguish between no arguments and one empty argument. @@ -812,6 +825,32 @@ sub ExpandMacro { @arguments = (); } + else + { + @arguments = &SplitArgs($args); + } + + # Test for empty arguments + my $have_empty_args = 0; + foreach my $arg (@arguments) + { + if ($arg eq '') + { + $have_empty_args = 1; + } + } + if ($have_empty_args) + { + if ($empty_args_error) + { + print STDERR "$filename:$linenumber: Error: Empty macro argument\n"; + ++ $errorcount; + } + elsif ($empty_args_warning) + { + print STDERR "$filename:$linenumber: Warning: Empty macro argument\n"; + } + } my $outstring = $defines{$macro}{"BODY"}; |