Generate hashCode and equals for unsigned types

This commit is contained in:
Ilya Gorbunov
2018-07-18 14:38:45 +03:00
parent e2310343d4
commit 1792a77a47
6 changed files with 47 additions and 0 deletions
+11
View File
@@ -229,6 +229,17 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
UnsignedType.ULONG -> out.println("ulongToString(data)")
else -> error(type)
}
out.println()
out.print(" public override fun hashCode(): Int = ")
when (type) {
UnsignedType.UBYTE, UnsignedType.USHORT, UnsignedType.UINT -> out.println("toInt()")
UnsignedType.ULONG -> out.println("((this shr 32).toInt() xor this.toInt())")
}
out.println()
out.println(" public override fun equals(other: Any?): Boolean =")
out.println(" other is ${type.capitalized} && this.data == other.data")
out.println()
}