diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index e158d6c..dc3a420 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -318,11 +318,11 @@ private: case schema::Value::INT8: return kj::strTree(value.getInt8()); 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(), "ll"); - case schema::Value::UINT8: return kj::strTree(value.getUint8(), "u"); - case schema::Value::UINT16: return kj::strTree(value.getUint16(), "u"); - case schema::Value::UINT32: return kj::strTree(value.getUint32(), "u"); - case schema::Value::UINT64: return kj::strTree(value.getUint64(), "llu"); + 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::FLOAT32: return kj::strTree(value.getFloat32(), "f"); case schema::Value::FLOAT64: return kj::strTree(value.getFloat64()); case schema::Value::ENUM: { @@ -1349,10 +1349,10 @@ private: case schema::Value::ENUM: return ConstText { false, - kj::strTree("static constexpr ", typeName_, ' ', upperCase, " = ", + kj::strTree("public static final ", typeName_, ' ', upperCase, " = ", literalValue(constProto.getType(), constProto.getValue()), ";\n"), scope.size() == 0 ? kj::strTree() : kj::strTree( - "constexpr ", typeName_, ' ', scope, upperCase, ";\n") + "final ", typeName_, ' ', scope, upperCase, ";\n") }; case schema::Value::TEXT: { @@ -1531,6 +1531,8 @@ private: scope, name, schema, KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }, indent); + KJ_LOG(ERROR, top.outerTypeDecl); + return NodeText { kj::mv(top.outerTypeDecl), @@ -1602,7 +1604,7 @@ private: auto enumerants = schema.asEnum().getEnumerants(); return NodeTextNoSchema { - kj::strTree(), + kj::strTree(), kj::strTree( spaces(indent), "public enum ", name, " {\n", @@ -1631,8 +1633,8 @@ private: auto constText = makeConstText(scope, name, schema.asConst()); return NodeTextNoSchema { - scope.size() == 0 ? kj::strTree() : kj::strTree(" ", kj::mv(constText.decl)), - scope.size() > 0 ? kj::strTree() : 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 8d09518..74e5173 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -32,6 +32,10 @@ class EncodingSuite extends FunSuite { } + test("Constants") { + assert(true == TestConstants.BOOL_CONST); + } + // 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 9bc95ef..ea89cb3 100644 --- a/compiler/src/test/schema/test.capnp +++ b/compiler/src/test/schema/test.capnp @@ -162,3 +162,19 @@ struct TestGroups { } } } + +struct TestConstants { +# const voidConst :Void = void; + const boolConst :Bool = true; + const int8Const :Int8 = -123; + 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 float32Const :Float32 = 1234.5; + const float64Const :Float64 = -123e45; +# ... +}