From f6f88e567ef7f2d282991c761ad2c8d106f6b183 Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 12 Jul 2016 19:47:53 +0200 Subject: [PATCH 1/5] Update idl_parser.cpp --- src/idl_parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index b758e9592..a5f325de4 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -423,6 +423,12 @@ CheckedError Parser::Next() { return NoError(); } else if (isdigit(static_cast(c)) || c == '-') { const char *start = cursor_ - 1; + if (c == '-' && *cursor_ == '0' && (cursor_[1] == 'x' || cursor_[1] == 'X')) { + ++start; + ++cursor_; + attribute_.append(&c, &c + 1); + c = '0'; + } if (c == '0' && (*cursor_ == 'x' || *cursor_ == 'X')) { cursor_++; while (isxdigit(static_cast(*cursor_))) cursor_++; From db99c1aa6462ac50b5eed23b775b43c08afff599 Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 12 Jul 2016 19:55:35 +0200 Subject: [PATCH 2/5] Update test.cpp --- tests/test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test.cpp b/tests/test.cpp index 6f3b06299..6cac364ae 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -837,6 +837,9 @@ void ValueTest() { // Test conversion functions. TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); + + // Test negative hex constant. + TEST_EQ(TestValue("{ Y:-0x80 }") == -128, true); } void EnumStringsTest() { From 676f0712fd23932c8d823278a1457a184765ceeb Mon Sep 17 00:00:00 2001 From: Raman Date: Thu, 14 Jul 2016 10:01:08 +0200 Subject: [PATCH 3/5] Update test.cpp --- tests/test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index 6cac364ae..06fa79af7 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -814,14 +814,14 @@ void ErrorTest() { TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once"); } -float TestValue(const char *json) { +template T TestValue(const char *json) { flatbuffers::Parser parser; // Simple schema. - TEST_EQ(parser.Parse("table X { Y:float; } root_type X;"), true); + TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(typeid(T).name()) + "; } root_type X;").c_str()), true); TEST_EQ(parser.Parse(json), true); - auto root = flatbuffers::GetRoot(parser.builder_.GetBufferPointer()); + auto root = flatbuffers::GetRoot(parser.builder_.GetBufferPointer()); // root will point to the table, which is a 32bit vtable offset followed // by a float: TEST_EQ(sizeof(flatbuffers::soffset_t), 4); // Test assumes 32bit offsets @@ -833,13 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; } // Additional parser testing not covered elsewhere. void ValueTest() { // Test scientific notation numbers. - TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), 3.14159), true); + TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), 3.14159), true); // Test conversion functions. - TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); + TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); // Test negative hex constant. - TEST_EQ(TestValue("{ Y:-0x80 }") == -128, true); + TEST_EQ(TestValue("{ Y:-0x80 }") == -128, true); } void EnumStringsTest() { From 98c7a0c169809d5ef294d6e4cd2bf43e59d64d7b Mon Sep 17 00:00:00 2001 From: Raman Date: Thu, 14 Jul 2016 10:30:06 +0200 Subject: [PATCH 4/5] Update test.cpp --- tests/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.cpp b/tests/test.cpp index 06fa79af7..4f817f060 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -833,7 +833,7 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; } // Additional parser testing not covered elsewhere. void ValueTest() { // Test scientific notation numbers. - TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), 3.14159), true); + TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), (float)3.14159), true); // Test conversion functions. TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); From 0d5627610261ee351aabfee626c2da87100ef08a Mon Sep 17 00:00:00 2001 From: Raman Date: Thu, 14 Jul 2016 18:51:23 +0200 Subject: [PATCH 5/5] Update test.cpp --- tests/test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index 4f817f060..209ec699f 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -814,11 +814,11 @@ void ErrorTest() { TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once"); } -template T TestValue(const char *json) { +template T TestValue(const char *json, const char *type_name) { flatbuffers::Parser parser; // Simple schema. - TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(typeid(T).name()) + "; } root_type X;").c_str()), true); + TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(type_name) + "; } root_type X;").c_str()), true); TEST_EQ(parser.Parse(json), true); auto root = flatbuffers::GetRoot(parser.builder_.GetBufferPointer()); @@ -833,13 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; } // Additional parser testing not covered elsewhere. void ValueTest() { // Test scientific notation numbers. - TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), (float)3.14159), true); + TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }","float"), (float)3.14159), true); // Test conversion functions. - TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); + TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }","float"), -1), true); // Test negative hex constant. - TEST_EQ(TestValue("{ Y:-0x80 }") == -128, true); + TEST_EQ(TestValue("{ Y:-0x80 }","int") == -128, true); } void EnumStringsTest() {