Partial handlling of 64-bit integer constants.

- Parse integer constants in Thrift files as 64-bit ints.
- Die if an overflow occurs.
- Warn if an enum value cannot fit in 32 bits.
- Add a simple test for the above.

I ran all of the generators over BrokenConstants.thrift before adding the
overflow, and they appeared to work.  However, the code generated was not
always valid (for example, the 64-bit constant must have an LL suffix in C++).


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@672907 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 21a0dd7..62cdb16 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -15,6 +15,8 @@
 
 %{
 
+#include <errno.h>
+
 #include "main.h"
 #include "globals.h"
 #include "parse/t_program.h"
@@ -30,6 +32,11 @@
   exit(1);
 }
 
+void integer_overflow(char* text) {
+  yyerror("This integer is too big: \"%s\"\n", text);
+  exit(1);
+}
+
 %}
 
 /**
@@ -181,12 +188,20 @@
 "yield"              { thrift_reserved_keyword(yytext); }
 
 {intconstant} {
-  yylval.iconst = atoi(yytext);
+  errno = 0;
+  yylval.iconst = strtoll(yytext, NULL, 10);
+  if (errno == ERANGE) {
+    integer_overflow(yytext);
+  }
   return tok_int_constant;
 }
 
 {hexconstant} {
-  sscanf(yytext+2, "%x", &yylval.iconst);
+  errno = 0;
+  yylval.iconst = strtoll(yytext+2, NULL, 16);
+  if (errno == ERANGE) {
+    integer_overflow(yytext);
+  }
   return tok_int_constant;
 }