CGrammar: Add _Static_assert

This commit is contained in:
Pragmatic Software 2014-07-07 08:27:10 +00:00
parent 9623086310
commit b470359071
3 changed files with 15 additions and 7 deletions

View File

@ -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;

View File

@ -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 <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <errno.h>\n#include <ctype.h>\n#include <assert.h>\n#include <stdnoreturn.h>\n#include <stdbool.h>\n#include <stdalign.h>\n\n";
my $prelude_base = "#define _XOPEN_SOURCE 9001\n#define __USE_XOPEN\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <errno.h>\n#include <ctype.h>\n#include <assert.h>\n#include <stdnoreturn.h>\n#include <stdbool.h>\n#include <stdalign.h>\n#define _Static_assert(a, b)\n\n";
my $prelude = $prelude_base;
print "code before: [$code]\n" if $debug;

View File

@ -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:
<leftop: init_declarator ',' init_declarator>
@ -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