From b470359071b2a7ed2ec93dd9bb07507374623a2a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 7 Jul 2014 08:27:10 +0000 Subject: [PATCH] CGrammar: Add _Static_assert --- PBot/VERSION.pm | 4 ++-- modules/c2english.pl | 2 +- modules/c2english/CGrammar.pm | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 2aed553d..2655a556 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 => 712, - BUILD_DATE => "2014-07-06", + BUILD_REVISION => 713, + BUILD_DATE => "2014-07-07", }; 1; diff --git a/modules/c2english.pl b/modules/c2english.pl index ff48abb9..eecaff36 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\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#define _Static_assert(a, b)\n\n"; my $prelude = $prelude_base; print "code before: [$code]\n" if $debug; diff --git a/modules/c2english/CGrammar.pm b/modules/c2english/CGrammar.pm index 1a7d0302..1ec592a5 100644 --- a/modules/c2english/CGrammar.pm +++ b/modules/c2english/CGrammar.pm @@ -633,6 +633,16 @@ cast_expression: | unary_expression { $return = $item{unary_expression}; } +Static_assert: + '_Static_assert' + | 'static_assert' + +static_assert_declaration: + Static_assert '(' constant_expression ',' string ')' ';' + { + $return = "Declare a static assertion to produce the diagnostic $item{string} if $item{constant_expression} is false.\n"; + } + declaration_list: preproc[context => 'statement'](?) declaration(s) { $return = join('', @{$item{'preproc(?)'}}) . join('', @{$item{'declaration(s)'}}); } @@ -832,6 +842,7 @@ declaration: } } } + | static_assert_declaration init_declarator_list: @@ -1817,9 +1828,6 @@ constant: } } -integer_constant: - /[0-9]+/ - identifier_word: /[a-z_\$][a-z0-9_]*/i { $return = "`$item[-1]`"; } @@ -1831,5 +1839,5 @@ reserved: /(auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto |if|inline|int|long|register|restrict|return|short|signed|sizeof|static|struct|switch|typedef |union|unsigned|void|volatile|while|_Alignas|alignas|_Alignof|alignof|_Atomic|_Bool|_Complex|_Generic - |_Imaginary|_Noreturn|_Static_assert|_Thread_local)\b/x + |_Imaginary|_Noreturn|noreturn|_Static_assert|static_assert|_Thread_local)\b/x