From 90e49fe3714844e1bab691dd7f2412b88196e0be Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Tue, 2 Sep 2014 19:32:33 -0400 Subject: [PATCH] handle large unsigned constants --- compiler/src/main/cpp/capnpc-java.c++ | 10 +++++----- .../src/test/scala/org/capnproto/EncodingTest.scala | 8 ++++++++ compiler/src/test/schema/test.capnp | 10 ++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index a405c66..ca36de2 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -319,10 +319,10 @@ private: case schema::Value::INT16: return kj::strTree(value.getInt16()); case schema::Value::INT32: return kj::strTree(value.getInt32()); case schema::Value::INT64: return kj::strTree(value.getInt64(), "L"); - case schema::Value::UINT8: return kj::strTree(value.getUint8()); - case schema::Value::UINT16: return kj::strTree(value.getUint16()); - case schema::Value::UINT32: return kj::strTree(value.getUint32()); - case schema::Value::UINT64: return kj::strTree(value.getUint64(), "L"); + case schema::Value::UINT8: return kj::strTree(static_cast(value.getUint8())); + case schema::Value::UINT16: return kj::strTree(static_cast(value.getUint16())); + case schema::Value::UINT32: return kj::strTree(static_cast(value.getUint32())); + case schema::Value::UINT64: return kj::strTree(static_cast(value.getUint64()), "L"); case schema::Value::FLOAT32: return kj::strTree(value.getFloat32(), "f"); case schema::Value::FLOAT64: return kj::strTree(value.getFloat64()); case schema::Value::ENUM: { @@ -1627,7 +1627,7 @@ private: auto constText = makeConstText(scope, name, schema.asConst()); return NodeTextNoSchema { - kj::mv(constText.decl), + kj::strTree(" ", kj::mv(constText.decl)), kj::strTree(), kj::strTree(), diff --git a/compiler/src/test/scala/org/capnproto/EncodingTest.scala b/compiler/src/test/scala/org/capnproto/EncodingTest.scala index 866032f..1e6068b 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -39,10 +39,18 @@ class EncodingSuite extends FunSuite { assert(-12345678 == TestConstants.INT32_CONST); assert(-123456789012345L == TestConstants.INT64_CONST); + assert(-22 == TestConstants.UINT8_CONST); + assert(-19858 == TestConstants.UINT16_CONST); + assert(-838178284 == TestConstants.UINT32_CONST); + assert(-6101065172474983726L == TestConstants.UINT64_CONST); + assert(1234.5f == TestConstants.FLOAT32_CONST); assert(-123e45 == TestConstants.FLOAT64_CONST); } + test("GlobalConstants") { + assert(12345 == GLOBAL_INT); + } // to debug, do this: //Serialize.writeMessage((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(), diff --git a/compiler/src/test/schema/test.capnp b/compiler/src/test/schema/test.capnp index ea89cb3..718ab6b 100644 --- a/compiler/src/test/schema/test.capnp +++ b/compiler/src/test/schema/test.capnp @@ -170,11 +170,13 @@ struct TestConstants { const int16Const :Int16 = -12345; const int32Const :Int32 = -12345678; const int64Const :Int64 = -123456789012345; -# const uint8Const :UInt8 = 234; -# const uint16Const :UInt16 = 45678; -# const uint32Const :UInt32 = 3456789012; -# const uint64Const :UInt64 = 12345678901234567890; + const uint8Const :UInt8 = 234; + const uint16Const :UInt16 = 45678; + const uint32Const :UInt32 = 3456789012; + const uint64Const :UInt64 = 12345678901234567890; const float32Const :Float32 = 1234.5; const float64Const :Float64 = -123e45; # ... } + +const globalInt :UInt32 = 12345; \ No newline at end of file