From 79796f9710d63c6dc81f9a46b5e3caab94338056 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 19 Sep 2014 04:17:37 +0000 Subject: [PATCH] CGrammar: Add istrue to static assertion expression; add ability to customize istrue truthiness result, add isfalse --- PBot/VERSION.pm | 2 +- modules/c2english.pl | 5 ++++- modules/c2english/CGrammar.pm | 5 +++-- modules/c2english/c2eng.pl | 9 +++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 4de9d772..26364047 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 788, + BUILD_REVISION => 789, BUILD_DATE => "2014-09-18", }; diff --git a/modules/c2english.pl b/modules/c2english.pl index 6f340e59..f9858e8a 100755 --- a/modules/c2english.pl +++ b/modules/c2english.pl @@ -19,7 +19,7 @@ if($code =~ s/^-f\s+//) { } my ($has_function, $has_main, $got_nomain); -my $prelude_base = "#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#define _Atomic\n#define _Static_assert(a, b)\n\n"; +my $prelude_base = "#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#define _Atomic\n#define _Static_assert(a, b)\n\n"; my $prelude = $prelude_base; print "code before: [$code]\n" if $debug; @@ -309,6 +309,9 @@ my ($ret, $result) = execute(10, "gcc -std=c11 -pedantic -Werror -Wno-unused -fs if(not $force and $ret != 0) { $output = $result; + #print STDERR "output: [$output]\n"; + + $output =~ s/\s*In file included from\s+.*?:\d+:\d+:\s*//g; $output =~ s/code\.c:\d+:\d+://g; $output =~ s/code\.c://g; $output =~ s/error=edantic/error=pedantic/g; diff --git a/modules/c2english/CGrammar.pm b/modules/c2english/CGrammar.pm index 4b939bbc..a478b189 100644 --- a/modules/c2english/CGrammar.pm +++ b/modules/c2english/CGrammar.pm @@ -695,9 +695,10 @@ Static_assert: | 'static_assert' static_assert_declaration: - Static_assert '(' constant_expression[context => 'static_assert'] ',' string ')' ';' + Static_assert '(' constant_expression[context => 'static assert'] ',' string ')' ';' { - $return = "Halt compilation and produce the diagnostic $item{string} unless $item{constant_expression}.\n"; + my $expression = ::istrue $item{constant_expression}; + $return = "Halt compilation and produce the diagnostic $item{string} unless $expression.\n"; } declaration_list: diff --git a/modules/c2english/c2eng.pl b/modules/c2english/c2eng.pl index c7fe4001..0ad294aa 100755 --- a/modules/c2english/c2eng.pl +++ b/modules/c2english/c2eng.pl @@ -101,19 +101,24 @@ sub flatten { map { ref eq 'ARRAY' ? flatten(@$_) : $_ } @_ } +sub isfalse { + return istrue($_[0], 'zero'); +} + sub istrue { my @parts = split /(?