Commit 9497b512 authored by Iulia Tamas's avatar Iulia Tamas Committed by Jacob Potter

Added f32 support.

Summary:
Changes in Java and Objc generators to differentiate between double and float. Added f32 as a
djinni primitive and in the djinni namespace.
parent c2fab0c0
......@@ -187,7 +187,7 @@ records (so a record cannot contain itself).
The available data types for a record are:
- Boolean (`bool`)
- Primitives (`i8`, `i16`, `i32`, `i64`, `f64`).
- Primitives (`i8`, `i16`, `i32`, `i64`, `f32`, `f64`).
- Strings (`string`)
- Binary (`binary`). This is implemented as `std::vector<uint8_t>` in C++, `byte[]` in Java,
and `NSData` in Objective-C.
......
......@@ -86,6 +86,7 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
case "i16" => "I16"
case "i32" => "I32"
case "i64" => "I64"
case "f32" => "F32"
case "f64" => "F64"
case "bool" => "Bool"
}
......
......@@ -66,6 +66,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
def writeJavaConst(w: IndentWriter, ty: TypeRef, v: Any): Unit = v match {
case l: Long => w.w(l.toString)
case d: Double if marshal.fieldType(ty) == "float" => w.w(d.toString + "f")
case d: Double => w.w(d.toString)
case b: Boolean => w.w(if (b) "true" else "false")
case s: String => w.w(s)
......
......@@ -80,6 +80,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
}
def writeObjcConstValue(w: IndentWriter, ty: TypeRef, v: Any): Unit = v match {
case l: Long => w.w(boxedPrimitive(ty) + l.toString)
case d: Double if marshal.fieldType(ty) == "float" => w.w(boxedPrimitive(ty) + d.toString + "f")
case d: Double => w.w(boxedPrimitive(ty) + d.toString)
case b: Boolean => w.w(boxedPrimitive(ty) + (if (b) "YES" else "NO"))
case s: String => w.w("@" + s)
......
......@@ -62,6 +62,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
case "i16" => "I16"
case "i32" => "I32"
case "i64" => "I64"
case "f32" => "F32"
case "f64" => "F64"
case "bool" => "Bool"
}
......
......@@ -51,6 +51,7 @@ val defaults: Map[String,MOpaque] = immutable.HashMap(
("i16", MPrimitive("i16", "short", "jshort", "int16_t", "Short", "S", "int16_t", "NSNumber")),
("i32", MPrimitive("i32", "int", "jint", "int32_t", "Integer", "I", "int32_t", "NSNumber")),
("i64", MPrimitive("i64", "long", "jlong", "int64_t", "Long", "J", "int64_t", "NSNumber")),
("f32", MPrimitive("f32", "float", "jfloat", "float", "Float", "F", "float", "NSNumber")),
("f64", MPrimitive("f64", "double", "jdouble", "double", "Double", "D", "double", "NSNumber")),
("bool", MPrimitive("bool", "boolean", "jboolean", "bool", "Boolean", "Z", "BOOL", "NSNumber")),
("string", MString),
......
......@@ -147,22 +147,26 @@ private def constTypeCheck(ty: MExpr, value: Any, resolvedConsts: Seq[Const]) {
if (!value.isInstanceOf[Boolean])
throw new AssertionError("Const type mismatch: bool")
case "i8" =>
try { value.asInstanceOf[Long].toByte } catch {
case e: Exception => throw new AssertionError("Const type mismatch: i8")
}
assert(value.isInstanceOf[Long], "Const type mismatch: i8")
assert(value.asInstanceOf[Long].toByte == value, "Const value not a valid i8")
case "i16" =>
try { value.asInstanceOf[Long].toShort } catch {
case e: Exception => throw new AssertionError("Const type mismatch: i16")
}
assert(value.isInstanceOf[Long], "Const type mismatch: i16")
assert(value.asInstanceOf[Long].toShort == value, "Const value not a valid i16")
case "i32" =>
try { value.asInstanceOf[Long].toInt } catch {
case e: Exception => throw new AssertionError("Const type mismatch: i32")
}
assert(value.isInstanceOf[Long], "Const type mismatch: i32")
assert(value.asInstanceOf[Long].toInt == value, "Const value not a valid i32")
case "i64" =>
if (!value.isInstanceOf[Long])
throw new AssertionError("Const type mismatch: i64")
assert(value.isInstanceOf[Long], "Const type mismatch: i64")
case "f32" => value match {
case i: Long =>
assert(i.toFloat == value, "Const value not a valid f32")
case f: Double =>
assert(f.toFloat == value, "Const value not a valid f32")
case _ => throw new AssertionError("Const type mismatch: f32")
}
case "f64" => value match {
case i: Long =>
assert(i.toDouble == value, "Const value not a valid f64")
case f: Double =>
case _ => throw new AssertionError("Const type mismatch: f64")
}
......
......@@ -114,7 +114,15 @@ namespace djinni
friend Primitive<I64, int64_t, jlong>;
static JniType unbox(JNIEnv* jniEnv, jmethodID method, jobject j) noexcept { return jniEnv->CallLongMethod(j, method); }
};
class F32 : public Primitive<F32, float, jfloat>
{
F32() : Primitive("java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", "floatValue", "()F") {}
friend JniClass<F32>;
friend Primitive<F32, float, jfloat>;
static JniType unbox(JNIEnv* jniEnv, jmethodID method, jobject j) noexcept { return jniEnv->CallFloatMethod(j, method); }
};
class F64 : public Primitive<F64, double, jdouble>
{
F64() : Primitive("java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", "doubleValue", "()D") {}
......
......@@ -72,6 +72,12 @@ class I64 : public Primitive<I64, int64_t> {
static Boxed::ObjcType box(CppType x) noexcept { return [NSNumber numberWithLongLong:static_cast<long long>(x)]; }
};
class F32 : public Primitive<F32, float> {
friend Primitive<F32, float>;
static CppType unbox(Boxed::ObjcType x) noexcept { return [x floatValue]; }
static Boxed::ObjcType box(CppType x) noexcept { return [NSNumber numberWithFloat:x]; }
};
class F64 : public Primitive<F64, double> {
friend Primitive<F64, double>;
static CppType unbox(Boxed::ObjcType x) noexcept { return [x doubleValue]; }
......
......@@ -7,6 +7,7 @@ constants = record {
const i16_constant: i16 = 2;
const i32_constant: i32 = 3;
const i64_constant: i64 = 4;
const f32_constant: f32 = 5.0;
const f64_constant: f64 = 5.0;
const string_constant: string = "string-constant";
const optional_integer_constant: optional<i32> = 1;
......@@ -23,6 +24,7 @@ constants_interface = interface +c {
const i16_constant: i16 = 2;
const i32_constant: i32 = 3;
const i64_constant: i64 = 4;
const f32_constant: f32 = 5.0;
const f64_constant: f64 = 5.0;
dummy();
......
......@@ -4,6 +4,7 @@ assorted_primitives = record {
sixteen: i16;
thirtytwo: i32;
sixtyfour: i64;
fthirtytwo: f32;
fsixtyfour: f64;
o_b: optional<bool>;
......@@ -11,5 +12,6 @@ assorted_primitives = record {
o_sixteen: optional<i16>;
o_thirtytwo: optional<i32>;
o_sixtyfour: optional<i64>;
o_fthirtytwo: optional<f32>;
o_fsixtyfour: optional<f64>;
} deriving (eq)
......@@ -10,12 +10,14 @@ bool operator==(const AssortedPrimitives& lhs, const AssortedPrimitives& rhs) {
lhs.sixteen == rhs.sixteen &&
lhs.thirtytwo == rhs.thirtytwo &&
lhs.sixtyfour == rhs.sixtyfour &&
lhs.fthirtytwo == rhs.fthirtytwo &&
lhs.fsixtyfour == rhs.fsixtyfour &&
lhs.o_b == rhs.o_b &&
lhs.o_eight == rhs.o_eight &&
lhs.o_sixteen == rhs.o_sixteen &&
lhs.o_thirtytwo == rhs.o_thirtytwo &&
lhs.o_sixtyfour == rhs.o_sixtyfour &&
lhs.o_fthirtytwo == rhs.o_fthirtytwo &&
lhs.o_fsixtyfour == rhs.o_fsixtyfour;
}
......
......@@ -13,12 +13,14 @@ struct AssortedPrimitives final {
int16_t sixteen;
int32_t thirtytwo;
int64_t sixtyfour;
float fthirtytwo;
double fsixtyfour;
std::experimental::optional<bool> o_b;
std::experimental::optional<int8_t> o_eight;
std::experimental::optional<int16_t> o_sixteen;
std::experimental::optional<int32_t> o_thirtytwo;
std::experimental::optional<int64_t> o_sixtyfour;
std::experimental::optional<float> o_fthirtytwo;
std::experimental::optional<double> o_fsixtyfour;
friend bool operator==(const AssortedPrimitives& lhs, const AssortedPrimitives& rhs);
......@@ -29,24 +31,28 @@ struct AssortedPrimitives final {
int16_t sixteen,
int32_t thirtytwo,
int64_t sixtyfour,
float fthirtytwo,
double fsixtyfour,
std::experimental::optional<bool> o_b,
std::experimental::optional<int8_t> o_eight,
std::experimental::optional<int16_t> o_sixteen,
std::experimental::optional<int32_t> o_thirtytwo,
std::experimental::optional<int64_t> o_sixtyfour,
std::experimental::optional<float> o_fthirtytwo,
std::experimental::optional<double> o_fsixtyfour)
: b(std::move(b))
, eight(std::move(eight))
, sixteen(std::move(sixteen))
, thirtytwo(std::move(thirtytwo))
, sixtyfour(std::move(sixtyfour))
, fthirtytwo(std::move(fthirtytwo))
, fsixtyfour(std::move(fsixtyfour))
, o_b(std::move(o_b))
, o_eight(std::move(o_eight))
, o_sixteen(std::move(o_sixteen))
, o_thirtytwo(std::move(o_thirtytwo))
, o_sixtyfour(std::move(o_sixtyfour))
, o_fthirtytwo(std::move(o_fthirtytwo))
, o_fsixtyfour(std::move(o_fsixtyfour))
{}
};
......@@ -13,6 +13,8 @@ int32_t const Constants::I32_CONSTANT = 3;
int64_t const Constants::I64_CONSTANT = 4;
float const Constants::F32_CONSTANT = 5.0;
double const Constants::F64_CONSTANT = 5.0;
std::string const Constants::STRING_CONSTANT = "string-constant";
......
......@@ -20,6 +20,8 @@ struct Constants final {
static int64_t const I64_CONSTANT;
static float const F32_CONSTANT;
static double const F64_CONSTANT;
static std::string const STRING_CONSTANT;
......
......@@ -13,4 +13,6 @@ int32_t const ConstantsInterface::I32_CONSTANT = 3;
int64_t const ConstantsInterface::I64_CONSTANT = 4;
float const ConstantsInterface::F32_CONSTANT = 5.0;
double const ConstantsInterface::F64_CONSTANT = 5.0;
......@@ -19,6 +19,8 @@ public:
static int64_t const I64_CONSTANT;
static float const F32_CONSTANT;
static double const F64_CONSTANT;
virtual void dummy() = 0;
......
......@@ -19,6 +19,8 @@ public final class AssortedPrimitives {
/*package*/ final long mSixtyfour;
/*package*/ final float mFthirtytwo;
/*package*/ final double mFsixtyfour;
/*package*/ final Boolean mOB;
......@@ -31,6 +33,8 @@ public final class AssortedPrimitives {
/*package*/ final Long mOSixtyfour;
/*package*/ final Float mOFthirtytwo;
/*package*/ final Double mOFsixtyfour;
public AssortedPrimitives(
......@@ -39,24 +43,28 @@ public final class AssortedPrimitives {
short sixteen,
int thirtytwo,
long sixtyfour,
float fthirtytwo,
double fsixtyfour,
@CheckForNull Boolean oB,
@CheckForNull Byte oEight,
@CheckForNull Short oSixteen,
@CheckForNull Integer oThirtytwo,
@CheckForNull Long oSixtyfour,
@CheckForNull Float oFthirtytwo,
@CheckForNull Double oFsixtyfour) {
this.mB = b;
this.mEight = eight;
this.mSixteen = sixteen;
this.mThirtytwo = thirtytwo;
this.mSixtyfour = sixtyfour;
this.mFthirtytwo = fthirtytwo;
this.mFsixtyfour = fsixtyfour;
this.mOB = oB;
this.mOEight = oEight;
this.mOSixteen = oSixteen;
this.mOThirtytwo = oThirtytwo;
this.mOSixtyfour = oSixtyfour;
this.mOFthirtytwo = oFthirtytwo;
this.mOFsixtyfour = oFsixtyfour;
}
......@@ -80,6 +88,10 @@ public final class AssortedPrimitives {
return mSixtyfour;
}
public float getFthirtytwo() {
return mFthirtytwo;
}
public double getFsixtyfour() {
return mFsixtyfour;
}
......@@ -109,6 +121,11 @@ public final class AssortedPrimitives {
return mOSixtyfour;
}
@CheckForNull
public Float getOFthirtytwo() {
return mOFthirtytwo;
}
@CheckForNull
public Double getOFsixtyfour() {
return mOFsixtyfour;
......@@ -125,12 +142,14 @@ public final class AssortedPrimitives {
this.mSixteen == other.mSixteen &&
this.mThirtytwo == other.mThirtytwo &&
this.mSixtyfour == other.mSixtyfour &&
this.mFthirtytwo == other.mFthirtytwo &&
this.mFsixtyfour == other.mFsixtyfour &&
((this.mOB == null && other.mOB == null) || (this.mOB != null && this.mOB.equals(other.mOB))) &&
((this.mOEight == null && other.mOEight == null) || (this.mOEight != null && this.mOEight.equals(other.mOEight))) &&
((this.mOSixteen == null && other.mOSixteen == null) || (this.mOSixteen != null && this.mOSixteen.equals(other.mOSixteen))) &&
((this.mOThirtytwo == null && other.mOThirtytwo == null) || (this.mOThirtytwo != null && this.mOThirtytwo.equals(other.mOThirtytwo))) &&
((this.mOSixtyfour == null && other.mOSixtyfour == null) || (this.mOSixtyfour != null && this.mOSixtyfour.equals(other.mOSixtyfour))) &&
((this.mOFthirtytwo == null && other.mOFthirtytwo == null) || (this.mOFthirtytwo != null && this.mOFthirtytwo.equals(other.mOFthirtytwo))) &&
((this.mOFsixtyfour == null && other.mOFsixtyfour == null) || (this.mOFsixtyfour != null && this.mOFsixtyfour.equals(other.mOFsixtyfour)));
}
}
......@@ -18,6 +18,8 @@ public final class Constants {
public static final long I64_CONSTANT = 4;
public static final float F32_CONSTANT = 5.0f;
public static final double F64_CONSTANT = 5.0;
@Nonnull
......
......@@ -18,6 +18,8 @@ public abstract class ConstantsInterface {
public static final long I64_CONSTANT = 4;
public static final float F32_CONSTANT = 5.0f;
public static final double F64_CONSTANT = 5.0;
public abstract void dummy();
......
......@@ -18,19 +18,21 @@ auto NativeAssortedPrimitives::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::dj
::djinni::I16::fromCpp(jniEnv, c.sixteen),
::djinni::I32::fromCpp(jniEnv, c.thirtytwo),
::djinni::I64::fromCpp(jniEnv, c.sixtyfour),
::djinni::F32::fromCpp(jniEnv, c.fthirtytwo),
::djinni::F64::fromCpp(jniEnv, c.fsixtyfour),
::djinni::Optional<std::experimental::optional, ::djinni::Bool>::fromCpp(jniEnv, c.o_b).get(),
::djinni::Optional<std::experimental::optional, ::djinni::I8>::fromCpp(jniEnv, c.o_eight).get(),
::djinni::Optional<std::experimental::optional, ::djinni::I16>::fromCpp(jniEnv, c.o_sixteen).get(),
::djinni::Optional<std::experimental::optional, ::djinni::I32>::fromCpp(jniEnv, c.o_thirtytwo).get(),
::djinni::Optional<std::experimental::optional, ::djinni::I64>::fromCpp(jniEnv, c.o_sixtyfour).get(),
::djinni::Optional<std::experimental::optional, ::djinni::F32>::fromCpp(jniEnv, c.o_fthirtytwo).get(),
::djinni::Optional<std::experimental::optional, ::djinni::F64>::fromCpp(jniEnv, c.o_fsixtyfour).get())};
::djinni::jniExceptionCheck(jniEnv);
return r;
}
auto NativeAssortedPrimitives::toCpp(JNIEnv* jniEnv, JniType j) -> CppType {
::djinni::JniLocalScope jscope(jniEnv, 13);
::djinni::JniLocalScope jscope(jniEnv, 15);
assert(j != nullptr);
const auto& data = ::djinni::JniClass<NativeAssortedPrimitives>::get();
return {::djinni::Bool::toCpp(jniEnv, jniEnv->GetBooleanField(j, data.field_mB)),
......@@ -38,12 +40,14 @@ auto NativeAssortedPrimitives::toCpp(JNIEnv* jniEnv, JniType j) -> CppType {
::djinni::I16::toCpp(jniEnv, jniEnv->GetShortField(j, data.field_mSixteen)),
::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mThirtytwo)),
::djinni::I64::toCpp(jniEnv, jniEnv->GetLongField(j, data.field_mSixtyfour)),
::djinni::F32::toCpp(jniEnv, jniEnv->GetFloatField(j, data.field_mFthirtytwo)),
::djinni::F64::toCpp(jniEnv, jniEnv->GetDoubleField(j, data.field_mFsixtyfour)),
::djinni::Optional<std::experimental::optional, ::djinni::Bool>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOB)),
::djinni::Optional<std::experimental::optional, ::djinni::I8>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOEight)),
::djinni::Optional<std::experimental::optional, ::djinni::I16>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOSixteen)),
::djinni::Optional<std::experimental::optional, ::djinni::I32>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOThirtytwo)),
::djinni::Optional<std::experimental::optional, ::djinni::I64>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOSixtyfour)),
::djinni::Optional<std::experimental::optional, ::djinni::F32>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOFthirtytwo)),
::djinni::Optional<std::experimental::optional, ::djinni::F64>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOFsixtyfour))};
}
......
......@@ -25,18 +25,20 @@ private:
friend ::djinni::JniClass<NativeAssortedPrimitives>;
const ::djinni::GlobalRef<jclass> clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/AssortedPrimitives") };
const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "<init>", "(ZBSIJDLjava/lang/Boolean;Ljava/lang/Byte;Ljava/lang/Short;Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/Double;)V") };
const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "<init>", "(ZBSIJFDLjava/lang/Boolean;Ljava/lang/Byte;Ljava/lang/Short;Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/Float;Ljava/lang/Double;)V") };
const jfieldID field_mB { ::djinni::jniGetFieldID(clazz.get(), "mB", "Z") };
const jfieldID field_mEight { ::djinni::jniGetFieldID(clazz.get(), "mEight", "B") };
const jfieldID field_mSixteen { ::djinni::jniGetFieldID(clazz.get(), "mSixteen", "S") };
const jfieldID field_mThirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mThirtytwo", "I") };
const jfieldID field_mSixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mSixtyfour", "J") };
const jfieldID field_mFthirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mFthirtytwo", "F") };
const jfieldID field_mFsixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mFsixtyfour", "D") };
const jfieldID field_mOB { ::djinni::jniGetFieldID(clazz.get(), "mOB", "Ljava/lang/Boolean;") };
const jfieldID field_mOEight { ::djinni::jniGetFieldID(clazz.get(), "mOEight", "Ljava/lang/Byte;") };
const jfieldID field_mOSixteen { ::djinni::jniGetFieldID(clazz.get(), "mOSixteen", "Ljava/lang/Short;") };
const jfieldID field_mOThirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mOThirtytwo", "Ljava/lang/Integer;") };
const jfieldID field_mOSixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mOSixtyfour", "Ljava/lang/Long;") };
const jfieldID field_mOFthirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mOFthirtytwo", "Ljava/lang/Float;") };
const jfieldID field_mOFsixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mOFsixtyfour", "Ljava/lang/Double;") };
};
......
......@@ -15,12 +15,14 @@ auto AssortedPrimitives::toCpp(ObjcType obj) -> CppType
::djinni::I16::toCpp(obj.sixteen),
::djinni::I32::toCpp(obj.thirtytwo),
::djinni::I64::toCpp(obj.sixtyfour),
::djinni::F32::toCpp(obj.fthirtytwo),
::djinni::F64::toCpp(obj.fsixtyfour),
::djinni::Optional<std::experimental::optional, ::djinni::Bool>::toCpp(obj.oB),
::djinni::Optional<std::experimental::optional, ::djinni::I8>::toCpp(obj.oEight),
::djinni::Optional<std::experimental::optional, ::djinni::I16>::toCpp(obj.oSixteen),
::djinni::Optional<std::experimental::optional, ::djinni::I32>::toCpp(obj.oThirtytwo),
::djinni::Optional<std::experimental::optional, ::djinni::I64>::toCpp(obj.oSixtyfour),
::djinni::Optional<std::experimental::optional, ::djinni::F32>::toCpp(obj.oFthirtytwo),
::djinni::Optional<std::experimental::optional, ::djinni::F64>::toCpp(obj.oFsixtyfour)};
}
......@@ -31,12 +33,14 @@ auto AssortedPrimitives::fromCpp(const CppType& cpp) -> ObjcType
sixteen:(::djinni::I16::fromCpp(cpp.sixteen))
thirtytwo:(::djinni::I32::fromCpp(cpp.thirtytwo))
sixtyfour:(::djinni::I64::fromCpp(cpp.sixtyfour))
fthirtytwo:(::djinni::F32::fromCpp(cpp.fthirtytwo))
fsixtyfour:(::djinni::F64::fromCpp(cpp.fsixtyfour))
oB:(::djinni::Optional<std::experimental::optional, ::djinni::Bool>::fromCpp(cpp.o_b))
oEight:(::djinni::Optional<std::experimental::optional, ::djinni::I8>::fromCpp(cpp.o_eight))
oSixteen:(::djinni::Optional<std::experimental::optional, ::djinni::I16>::fromCpp(cpp.o_sixteen))
oThirtytwo:(::djinni::Optional<std::experimental::optional, ::djinni::I32>::fromCpp(cpp.o_thirtytwo))
oSixtyfour:(::djinni::Optional<std::experimental::optional, ::djinni::I64>::fromCpp(cpp.o_sixtyfour))
oFthirtytwo:(::djinni::Optional<std::experimental::optional, ::djinni::F32>::fromCpp(cpp.o_fthirtytwo))
oFsixtyfour:(::djinni::Optional<std::experimental::optional, ::djinni::F64>::fromCpp(cpp.o_fsixtyfour))];
}
......
......@@ -9,12 +9,14 @@
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
oB:(nullable NSNumber *)oB
oEight:(nullable NSNumber *)oEight
oSixteen:(nullable NSNumber *)oSixteen
oThirtytwo:(nullable NSNumber *)oThirtytwo
oSixtyfour:(nullable NSNumber *)oSixtyfour
oFthirtytwo:(nullable NSNumber *)oFthirtytwo
oFsixtyfour:(nullable NSNumber *)oFsixtyfour;
@property (nonatomic, readonly) BOOL b;
......@@ -27,6 +29,8 @@
@property (nonatomic, readonly) int64_t sixtyfour;
@property (nonatomic, readonly) float fthirtytwo;
@property (nonatomic, readonly) double fsixtyfour;
@property (nonatomic, readonly, nullable) NSNumber * oB;
......@@ -39,6 +43,8 @@
@property (nonatomic, readonly, nullable) NSNumber * oSixtyfour;
@property (nonatomic, readonly, nullable) NSNumber * oFthirtytwo;
@property (nonatomic, readonly, nullable) NSNumber * oFsixtyfour;
@end
......@@ -11,12 +11,14 @@
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
oB:(nullable NSNumber *)oB
oEight:(nullable NSNumber *)oEight
oSixteen:(nullable NSNumber *)oSixteen
oThirtytwo:(nullable NSNumber *)oThirtytwo
oSixtyfour:(nullable NSNumber *)oSixtyfour
oFthirtytwo:(nullable NSNumber *)oFthirtytwo
oFsixtyfour:(nullable NSNumber *)oFsixtyfour
{
if (self = [super init]) {
......@@ -25,12 +27,14 @@
_sixteen = sixteen;
_thirtytwo = thirtytwo;
_sixtyfour = sixtyfour;
_fthirtytwo = fthirtytwo;
_fsixtyfour = fsixtyfour;
_oB = oB;
_oEight = oEight;
_oSixteen = oSixteen;
_oThirtytwo = oThirtytwo;
_oSixtyfour = oSixtyfour;
_oFthirtytwo = oFthirtytwo;
_oFsixtyfour = oFsixtyfour;
}
return self;
......@@ -47,12 +51,14 @@
self.sixteen == typedOther.sixteen &&
self.thirtytwo == typedOther.thirtytwo &&
self.sixtyfour == typedOther.sixtyfour &&
self.fthirtytwo == typedOther.fthirtytwo &&
self.fsixtyfour == typedOther.fsixtyfour &&
((self.oB == nil && typedOther.oB == nil) || (self.oB != nil && [self.oB isEqual:typedOther.oB])) &&
((self.oEight == nil && typedOther.oEight == nil) || (self.oEight != nil && [self.oEight isEqual:typedOther.oEight])) &&
((self.oSixteen == nil && typedOther.oSixteen == nil) || (self.oSixteen != nil && [self.oSixteen isEqual:typedOther.oSixteen])) &&
((self.oThirtytwo == nil && typedOther.oThirtytwo == nil) || (self.oThirtytwo != nil && [self.oThirtytwo isEqual:typedOther.oThirtytwo])) &&
((self.oSixtyfour == nil && typedOther.oSixtyfour == nil) || (self.oSixtyfour != nil && [self.oSixtyfour isEqual:typedOther.oSixtyfour])) &&
((self.oFthirtytwo == nil && typedOther.oFthirtytwo == nil) || (self.oFthirtytwo != nil && [self.oFthirtytwo isEqual:typedOther.oFthirtytwo])) &&
((self.oFsixtyfour == nil && typedOther.oFsixtyfour == nil) || (self.oFsixtyfour != nil && [self.oFsixtyfour isEqual:typedOther.oFsixtyfour]));
}
......@@ -64,12 +70,14 @@
(NSUInteger)self.sixteen ^
(NSUInteger)self.thirtytwo ^
(NSUInteger)self.sixtyfour ^
(NSUInteger)self.fthirtytwo ^
(NSUInteger)self.fsixtyfour ^
self.oB.hash ^
self.oEight.hash ^
self.oSixteen.hash ^
self.oThirtytwo.hash ^
self.oSixtyfour.hash ^
self.oFthirtytwo.hash ^
self.oFsixtyfour.hash;
}
......
......@@ -19,6 +19,7 @@ extern int8_t const DBConstantsI8Constant;
extern int16_t const DBConstantsI16Constant;
extern int32_t const DBConstantsI32Constant;
extern int64_t const DBConstantsI64Constant;
extern float const DBConstantsF32Constant;
extern double const DBConstantsF64Constant;
extern NSString * __nonnull const DBConstantsStringConstant;
extern NSNumber * __nullable const DBConstantsOptionalIntegerConstant;
......
......@@ -16,6 +16,8 @@ int32_t const DBConstantsI32Constant = 3;
int64_t const DBConstantsI64Constant = 4;
float const DBConstantsF32Constant = 5.0f;
double const DBConstantsF64Constant = 5.0;
NSString * __nonnull const DBConstantsStringConstant = @"string-constant";
......
......@@ -8,6 +8,7 @@ extern int8_t const DBConstantsInterfaceI8Constant;
extern int16_t const DBConstantsInterfaceI16Constant;
extern int32_t const DBConstantsInterfaceI32Constant;
extern int64_t const DBConstantsInterfaceI64Constant;
extern float const DBConstantsInterfaceF32Constant;
extern double const DBConstantsInterfaceF64Constant;
@interface DBConstantsInterface : NSObject
......
......@@ -16,6 +16,8 @@ int32_t const DBConstantsInterfaceI32Constant = 3;
int64_t const DBConstantsInterfaceI64Constant = 4;
float const DBConstantsInterfaceF32Constant = 5.0f;
double const DBConstantsInterfaceF64Constant = 5.0;
#pragma clang diagnostic pop
......@@ -5,8 +5,8 @@ import junit.framework.TestCase;
public class PrimitivesTest extends TestCase {
public void testPrimitives() {
AssortedPrimitives p = new AssortedPrimitives(true, (byte)123, (short)20000, 1000000000, 1234567890123456789L, 1.23d,
true, (byte)123, (short)20000, 1000000000, 1234567890123456789L, 1.23d);
AssortedPrimitives p = new AssortedPrimitives(true, (byte)123, (short)20000, 1000000000, 1234567890123456789L, 1.23f, 1.23d,
true, (byte)123, (short)20000, 1000000000, 1234567890123456789L, 1.23f, 1.23d);
assertEquals(p, TestHelpers.assortedPrimitivesId(p));
}
......
......@@ -29,13 +29,15 @@
sixteen:(int16_t)20000
thirtytwo:(int32_t)1000000000
sixtyfour:(int64_t)1234567890123456789L
fsixtyfour:1.23L
fthirtytwo:(float)1.23
fsixtyfour:1.23
oB:[NSNumber numberWithBool:YES]
oEight:[NSNumber numberWithChar:123]
oSixteen:[NSNumber numberWithShort:20000]
oThirtytwo:[NSNumber numberWithInt:1000000000]
oSixtyfour:[NSNumber numberWithLongLong:1234567890123456789L]
oFsixtyfour:[NSNumber numberWithDouble:123L]];
oFthirtytwo:[NSNumber numberWithFloat:(float)123]
oFsixtyfour:[NSNumber numberWithDouble:123]];
XCTAssertEqualObjects(p, [DBTestHelpers assortedPrimitivesId:p]);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment