From 527e8490a33ada8800ba611d68992d4d64c64b83 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 10 Aug 2014 05:03:37 +0000 Subject: [PATCH] CGrammar: Add offsetof --- PBot/VERSION.pm | 4 ++-- modules/c2english/CGrammar.pm | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 5f7966b0..f658db29 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 => 770, - BUILD_DATE => "2014-08-05", + BUILD_REVISION => 771, + BUILD_DATE => "2014-08-09", }; 1; diff --git a/modules/c2english/CGrammar.pm b/modules/c2english/CGrammar.pm index 21038441..6d5151fb 100644 --- a/modules/c2english/CGrammar.pm +++ b/modules/c2english/CGrammar.pm @@ -628,6 +628,7 @@ logical_OR_AND_expression: and $expression =~ / / and $expression !~ /^the .*? number \S+$/i and $expression !~ /the size of/i + and $expression !~ /the offset/i and $expression !~ /^the result of the/) { $return = 'the result of the expression ^L'; } @@ -1037,6 +1038,10 @@ unary_expression: } | Alignof '(' type_name ')' { $return = "the alignment of the type $item{type_name}"; } + | 'offsetof' '(' type_name[context => 'offsetof'] ',' identifier ')' + { + $return = "the offset, in bytes, of member $item{identifier} from the beginning of $item{type_name}"; + } Alignof: '_Alignof' @@ -1925,5 +1930,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|noreturn|_Static_assert|static_assert|_Thread_local)\b/x + |_Imaginary|_Noreturn|noreturn|_Static_assert|static_assert|_Thread_local|offsetof)\b/x