From e93ac26062ee8f6215efefd5f2d085cd03575930 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 21 Nov 2012 19:01:10 +0000 Subject: [PATCH] compiler_vm: Warn about #defines not terminated with \n --- PBot/VERSION.pm | 4 ++-- modules/compiler_vm/compiler_vm_client.pl | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 4e903402..828924e4 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 397, - BUILD_DATE => "2012-11-19", + BUILD_REVISION => 398, + BUILD_DATE => "2012-11-21", }; 1; diff --git a/modules/compiler_vm/compiler_vm_client.pl b/modules/compiler_vm/compiler_vm_client.pl index 9796c87c..65bce9bf 100755 --- a/modules/compiler_vm/compiler_vm_client.pl +++ b/modules/compiler_vm/compiler_vm_client.pl @@ -17,6 +17,8 @@ my $MAX_UNDO_HISTORY = 1000000; my $output = ""; my $nooutput = 'No output.'; +my $warn_unterminated_define = 0; + my %languages = ( 'C11' => "gcc -std=c11 -pedantic -Wall -Wextra (default)", 'C99' => "gcc -std=c99 -pedantic -Wall -Wextra", @@ -26,7 +28,7 @@ my %languages = ( my %preludes = ( 'C99' => "#define _XOPEN_SOURCE 9001\n#define __USE_XOPEN\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n", 'C11' => "#define _XOPEN_SOURCE 9001\n#define __USE_XOPEN\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n", - 'C' => "#define _XOPEN_SOURCE 9001\n#define __USE_XOPEN\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n", + 'C89' => "#define _XOPEN_SOURCE 9001\n#define __USE_XOPEN\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n", ); sub pretty { @@ -726,7 +728,7 @@ $code = ''; print "--- precode: [$precode]\n" if $debug; -if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { +if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { my $has_main = 0; my $prelude = ''; @@ -734,6 +736,14 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { $prelude .= $1; } + if($precode =~ m/^\s*(#.*)/m) { + my $line = $1; + + if($line !~ m/\n/) { + $warn_unterminated_define = 1; + } + } + print "*** prelude: [$prelude]\n precode: [$precode]\n" if $debug; # strip C and C++ style comments @@ -937,6 +947,14 @@ if($output =~ m/^\s*$/) { $output =~ s/ called by \?\? \(\)//g; } +if($warn_unterminated_define == 1) { + if($output =~ m/^\[(warning:|info:)/) { + $output =~ s/^\[/[notice: #define not terminated by \\n, the remainder of the line will be part of this #define /; + } else { + $output =~ s/^/[notice: #define not terminated by \\n, the remainder of the line will be part of this #define] /; + } +} + unless($got_run) { print FILE "$nick: $output\n"; close FILE;