Repository: thrift Updated Branches: refs/heads/master 71f2d8a71 -> 811d279d5
THRIFT-233 IDL doesn't support negative hex literals Client: Compiler general Patch: mreve <[email protected]> This closes #461 Update hexconstant regex in thriftl.ll As it is now, the parser doesn't allow hex constant values to be negative (it throws a 'bad syntax' error).The change updates the regex and the part that parses the hex value from the string read from the IDL file to support negative values. Add test to ConstantsDemo.thrift Before the change, "make install" would break with negative hex constant in ConstantsDemo.thrift. Now it compiles. Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/5ec2121c Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/5ec2121c Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/5ec2121c Branch: refs/heads/master Commit: 5ec2121cf283e8d708d22ab3e66c9c7103ecbaf0 Parents: 71f2d8a Author: Jens Geyer <[email protected]> Authored: Sun Apr 26 15:24:59 2015 +0200 Committer: Jens Geyer <[email protected]> Committed: Sun Apr 26 17:47:43 2015 +0200 ---------------------------------------------------------------------- compiler/cpp/src/thriftl.ll | 9 +++++++-- test/ConstantsDemo.thrift | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/5ec2121c/compiler/cpp/src/thriftl.ll ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll index 5afc601..a8ffe57 100644 --- a/compiler/cpp/src/thriftl.ll +++ b/compiler/cpp/src/thriftl.ll @@ -104,7 +104,7 @@ void unexpected_token(char* text) { */ intconstant ([+-]?[0-9]+) -hexconstant ("0x"[0-9A-Fa-f]+) +hexconstant ([+-]?"0x"[0-9A-Fa-f]+) dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?) identifier ([a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*) whitespace ([ \t\r\n]*) @@ -305,7 +305,12 @@ literal_begin (['\"]) {hexconstant} { errno = 0; - yylval.iconst = strtoll(yytext+2, NULL, 16); + char sign = yytext[0]; + int shift = sign == '0' ? 2 : 3; + yylval.iconst = strtoll(yytext+shift, NULL, 16); + if (sign == '-') { + yylval.iconst = -yylval.iconst; + } if (errno == ERANGE) { integer_overflow(yytext); } http://git-wip-us.apache.org/repos/asf/thrift/blob/5ec2121c/test/ConstantsDemo.thrift ---------------------------------------------------------------------- diff --git a/test/ConstantsDemo.thrift b/test/ConstantsDemo.thrift index 7d971e6..9a71ac8 100644 --- a/test/ConstantsDemo.thrift +++ b/test/ConstantsDemo.thrift @@ -40,6 +40,7 @@ const myIntType myInt = 3 //const map<enumconstants,string> GEN_ENUM_NAMES = {ONE : "HOWDY", TWO: "PARTNER"} const i32 hex_const = 0x0001F +const i32 negative_hex_constant = -0x0001F const i32 GEN_ME = -3523553 const double GEn_DUB = 325.532
