diff --git a/bindgen/ir/Enum.cpp b/bindgen/ir/Enum.cpp index f2dbaa3..80116f2 100644 --- a/bindgen/ir/Enum.cpp +++ b/bindgen/ir/Enum.cpp @@ -13,46 +13,30 @@ Enum::Enum(std::string name, std::string type, : PrimitiveType(std::move(type)), LocatableType(std::move(location)), name(std::move(name)), enumerators(std::move(enumerators)) {} -bool Enum::isAnonymous() const { return name.empty(); } - -std::string Enum::getDefinition() { - return " type " + getTypeAlias() + " = " + PrimitiveType::str() + "\n"; -} - -llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Enum &e) { - for (auto enumerator : e.enumerators) { - std::string enumeratorName; - if (!e.name.empty()) { - enumeratorName = "enum_" + e.name + "_" + enumerator.getName(); - } else { - enumeratorName = "enum_" + enumerator.getName(); - } - s << " final val " << enumeratorName; - std::string type; - if (e.isAnonymous()) { - type = e.getType(); - } else { - type = "enum_" + e.name; - } - s << ": " << type << " = " << std::to_string(enumerator.getValue()); - - if (e.getType() == "native.CLong") { - s << "L"; - } else if (e.getType() == "native.CUnsignedInt") { - s << ".toUInt"; - } else if (e.getType() == "native.CUnsignedLong") { - s << "L.toULong"; - } - s << "\n"; +std::string Enum::getEnumerators() const { + std::stringstream s; + std::string typeCastSuffix = getTypeCastSuffix(); + std::string type = getTypeAlias(); + s << " object " << type << " {\n"; + for (auto enumerator : enumerators) { + s << " final val " << enumerator.getName(); + s << ": " << type << " = " << std::to_string(enumerator.getValue()) + << typeCastSuffix << "\n"; } - return s; + s << " }\n"; + return s.str(); } -std::string Enum::getName() const { return name; } - -std::string Enum::getTypeAlias() const { - assert(!isAnonymous()); - return "enum_" + name; +std::string Enum::getTypeCastSuffix() const { + std::string primitiveType = PrimitiveType::getType(); + if (primitiveType == "native.CLong") { + return "L"; + } else if (primitiveType == "native.CUnsignedInt") { + return ".toUInt"; + } else if (primitiveType == "native.CUnsignedLong") { + return "L.toULong"; + } + return ""; } std::string Enum::str(const LocationManager &locationManager) const { @@ -61,3 +45,11 @@ std::string Enum::str(const LocationManager &locationManager) const { } return getTypeAlias(); } + +std::string Enum::getTypeAlias() const { return "enum_" + name; } + +std::string Enum::getDefinition() const { + return " type " + getTypeAlias() + " = " + PrimitiveType::str() + "\n"; +} + +std::string Enum::getName() const { return name; } diff --git a/bindgen/ir/Enum.h b/bindgen/ir/Enum.h index 899993f..0d20155 100644 --- a/bindgen/ir/Enum.h +++ b/bindgen/ir/Enum.h @@ -25,21 +25,26 @@ class Enum : public PrimitiveType, public LocatableType { std::vector enumerators, std::shared_ptr location); - bool isAnonymous() const; + /** + * @return a string that contains all enumerators. + * If enum is not anonymous then enumerators are inside an object + * with the same name as enum type. + */ + std::string getEnumerators() const; - std::string getDefinition(); + std::string str(const LocationManager &locationManager) const override; std::string getName() const; - friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Enum &e); - - std::string getTypeAlias() const; - - std::string str(const LocationManager &locationManager) const override; + std::string getDefinition() const; private: - std::string name; // might be empty + std::string name; // non-empty std::vector enumerators; + + std::string getTypeCastSuffix() const; + + std::string getTypeAlias() const; }; #endif // SCALA_NATIVE_BINDGEN_ENUM_H diff --git a/bindgen/ir/IR.cpp b/bindgen/ir/IR.cpp index b5bdb9f..ca476d1 100644 --- a/bindgen/ir/IR.cpp +++ b/bindgen/ir/IR.cpp @@ -27,9 +27,7 @@ std::shared_ptr IR::addEnum(std::string name, const std::string &type, std::shared_ptr location) { std::shared_ptr e = std::make_shared( std::move(name), type, std::move(enumerators), std::move(location)); - enums.push_back(e); - return e; } @@ -122,8 +120,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) { for (const auto &e : ir.enums) { visitedTypes.clear(); - if (!e->isAnonymous() && ir.shouldOutput(e, visitedTypes)) { + if (ir.shouldOutput(e, visitedTypes)) { s << e->getDefinition(); + s << e->getEnumerators() << "\n"; } } @@ -184,25 +183,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) { s << "}\n\n"; } - if (ir.shouldOutputType(ir.enums) || ir.hasHelperMethods()) { + if (ir.hasHelperMethods()) { s << "import " << objectName << "._\n\n"; } - if (ir.shouldOutputType(ir.enums)) { - s << "object " << ir.libName << "Enums {\n"; - - std::string sep = ""; - for (const auto &e : ir.enums) { - visitedTypes.clear(); - if (ir.shouldOutput(e, visitedTypes)) { - s << sep << *e; - sep = "\n"; - } - } - - s << "}\n\n"; - } - if (ir.hasHelperMethods()) { s << "object " << ir.libName << "Helpers {\n"; diff --git a/bindgen/visitor/TreeVisitor.cpp b/bindgen/visitor/TreeVisitor.cpp index b952ebe..8f210a5 100644 --- a/bindgen/visitor/TreeVisitor.cpp +++ b/bindgen/visitor/TreeVisitor.cpp @@ -74,11 +74,16 @@ bool TreeVisitor::VisitEnumDecl(clang::EnumDecl *enumDecl) { std::string scalaType = typeTranslator.getTypeFromTypeMap( enumDecl->getIntegerType().getUnqualifiedType().getAsString()); + std::shared_ptr location = typeTranslator.getLocation(enumDecl); + if (name.empty()) { + name = "anonymous_" + std::to_string(anonymousEnumId++); + } std::shared_ptr e = - ir.addEnum(name, scalaType, std::move(enumerators), - typeTranslator.getLocation(enumDecl)); + ir.addEnum(name, scalaType, std::move(enumerators), location); if (typedefName) { + /* add alias here because in VisitTypedefDecl it will be difficult to + * match typedef with enum */ ir.addTypeDef(name, e, typeTranslator.getLocation(typedefName)); } diff --git a/bindgen/visitor/TreeVisitor.h b/bindgen/visitor/TreeVisitor.h index 071cde9..14ab8c4 100644 --- a/bindgen/visitor/TreeVisitor.h +++ b/bindgen/visitor/TreeVisitor.h @@ -10,6 +10,7 @@ class TreeVisitor : public clang::RecursiveASTVisitor { clang::ASTContext *astContext; TypeTranslator typeTranslator; IR &ir; + uint anonymousEnumId = 0; bool isAliasForAnonymousEnum(clang::TypedefDecl *tpdef) const; diff --git a/tests/samples/CustomNames.scala b/tests/samples/CustomNames.scala index 421d1f1..a6cfd8f 100644 --- a/tests/samples/CustomNames.scala +++ b/tests/samples/CustomNames.scala @@ -6,6 +6,12 @@ import scala.scalanative.native._ @native.link("bindgentests") @native.extern object CustomNames { + type enum_enumWithTypedef = native.CUnsignedInt + object enum_enumWithTypedef { + final val CONST: enum_enumWithTypedef = 0.toUInt + } + + type EnumWithTypedef = enum_enumWithTypedef type page = native.CStruct2[native.CString, native.Ptr[Byte]] type book = native.CStruct1[native.Ptr[page]] type MY_INT = native.CInt diff --git a/tests/samples/Enum.scala b/tests/samples/Enum.scala index d61136e..d11d4a3 100644 --- a/tests/samples/Enum.scala +++ b/tests/samples/Enum.scala @@ -7,33 +7,40 @@ import scala.scalanative.native._ @native.extern object Enum { type enum_days = native.CUnsignedInt - type enum_bigValues = native.CUnsignedLong - type enum_negativeValues = native.CInt - type enum_bigNegativeValues = native.CLong - def get_WEDNESDAY(): enum_days = native.extern - def check_BIG_NEG_A(big_neg_a: enum_bigNegativeValues): native.CString = native.extern -} + object enum_days { + final val MONDAY: enum_days = 0.toUInt + final val TUESDAY: enum_days = 200.toUInt + final val WEDNESDAY: enum_days = 201.toUInt + final val THURSDAY: enum_days = 4.toUInt + final val FRIDAY: enum_days = 5.toUInt + final val SATURDAY: enum_days = 3.toUInt + final val SUNDAY: enum_days = 4.toUInt + } -import Enum._ - -object EnumEnums { - final val enum_days_MONDAY: enum_days = 0.toUInt - final val enum_days_TUESDAY: enum_days = 200.toUInt - final val enum_days_WEDNESDAY: enum_days = 201.toUInt - final val enum_days_THURSDAY: enum_days = 4.toUInt - final val enum_days_FRIDAY: enum_days = 5.toUInt - final val enum_days_SATURDAY: enum_days = 3.toUInt - final val enum_days_SUNDAY: enum_days = 4.toUInt + type enum_bigValues = native.CUnsignedLong + object enum_bigValues { + final val BIG_A: enum_bigValues = 10000000000L.toULong + final val BIG_B: enum_bigValues = 1L.toULong + } - final val enum_bigValues_BIG_A: enum_bigValues = 10000000000L.toULong - final val enum_bigValues_BIG_B: enum_bigValues = 1L.toULong + type enum_anonymous_0 = native.CUnsignedInt + object enum_anonymous_0 { + final val ANON_A: enum_anonymous_0 = 0.toUInt + final val ANON_B: enum_anonymous_0 = 1.toUInt + } - final val enum_ANON_A: native.CUnsignedInt = 0.toUInt - final val enum_ANON_B: native.CUnsignedInt = 1.toUInt + type enum_negativeValues = native.CInt + object enum_negativeValues { + final val NEG_A: enum_negativeValues = -1 + final val NEG_B: enum_negativeValues = -2 + } - final val enum_negativeValues_NEG_A: enum_negativeValues = -1 - final val enum_negativeValues_NEG_B: enum_negativeValues = -2 + type enum_bigNegativeValues = native.CLong + object enum_bigNegativeValues { + final val BIG_NEG_A: enum_bigNegativeValues = -10000000000L + final val BIG_NEG_B: enum_bigNegativeValues = -1L + } - final val enum_bigNegativeValues_BIG_NEG_A: enum_bigNegativeValues = -10000000000L - final val enum_bigNegativeValues_BIG_NEG_B: enum_bigNegativeValues = -1L + def get_WEDNESDAY(): enum_days = native.extern + def check_BIG_NEG_A(big_neg_a: enum_bigNegativeValues): native.CString = native.extern } diff --git a/tests/samples/Extern.scala b/tests/samples/Extern.scala index ad60e7e..c726c41 100644 --- a/tests/samples/Extern.scala +++ b/tests/samples/Extern.scala @@ -7,6 +7,11 @@ import scala.scalanative.native._ @native.extern object Extern { type enum_mode = native.CUnsignedInt + object enum_mode { + final val SYSTEM: enum_mode = 0.toUInt + final val USER: enum_mode = 1.toUInt + } + type struct_version = native.CStruct3[native.CInt, native.CInt, native.CInt] val forty_two: native.CInt = native.extern val version: native.CString = native.extern @@ -16,11 +21,6 @@ object Extern { import Extern._ -object ExternEnums { - final val enum_mode_SYSTEM: enum_mode = 0.toUInt - final val enum_mode_USER: enum_mode = 1.toUInt -} - object ExternHelpers { implicit class struct_version_ops(val p: native.Ptr[struct_version]) extends AnyVal { diff --git a/tests/samples/IncludesHeader.scala b/tests/samples/IncludesHeader.scala index b08d3eb..90f16e9 100644 --- a/tests/samples/IncludesHeader.scala +++ b/tests/samples/IncludesHeader.scala @@ -7,6 +7,11 @@ import scala.scalanative.native._ @native.extern object IncludesHeader { type enum_semester = native.CUnsignedInt + object enum_semester { + final val AUTUMN: enum_semester = 0.toUInt + final val SPRING: enum_semester = 1.toUInt + } + type size = native.CInt type struct_metadata = native.CStruct2[native.CUnsignedInt, native.CString] type metadata = struct_metadata @@ -17,11 +22,6 @@ object IncludesHeader { import IncludesHeader._ -object IncludesHeaderEnums { - final val enum_semester_AUTUMN: enum_semester = 0.toUInt - final val enum_semester_SPRING: enum_semester = 1.toUInt -} - object IncludesHeaderHelpers { implicit class struct_metadata_ops(val p: native.Ptr[struct_metadata]) extends AnyVal { diff --git a/tests/samples/PrivateMembers.scala b/tests/samples/PrivateMembers.scala index ebca35e..c5634b2 100644 --- a/tests/samples/PrivateMembers.scala +++ b/tests/samples/PrivateMembers.scala @@ -7,7 +7,23 @@ import scala.scalanative.native._ @native.extern object PrivateMembers { type enum___privateEnum = native.CUnsignedInt + object enum___privateEnum { + final val A: enum___privateEnum = 0.toUInt + final val B: enum___privateEnum = 1.toUInt + } + type enum_enumWithPrivateMembers = native.CUnsignedInt + object enum_enumWithPrivateMembers { + final val __C: enum_enumWithPrivateMembers = 0.toUInt + final val D: enum_enumWithPrivateMembers = 1.toUInt + } + + type enum_anonymous_0 = native.CUnsignedInt + object enum_anonymous_0 { + final val __E: enum_anonymous_0 = 0.toUInt + final val F: enum_anonymous_0 = 1.toUInt + } + type pid_t = native.CInt type __private_type = native.CInt type struct_structWithPrivateType = native.CStruct2[native.CInt, __private_type] @@ -26,17 +42,6 @@ object PrivateMembers { import PrivateMembers._ -object PrivateMembersEnums { - final val enum___privateEnum_A: enum___privateEnum = 0.toUInt - final val enum___privateEnum_B: enum___privateEnum = 1.toUInt - - final val enum_enumWithPrivateMembers___C: enum_enumWithPrivateMembers = 0.toUInt - final val enum_enumWithPrivateMembers_D: enum_enumWithPrivateMembers = 1.toUInt - - final val enum___E: native.CUnsignedInt = 0.toUInt - final val enum_F: native.CUnsignedInt = 1.toUInt -} - object PrivateMembersHelpers { implicit class struct_structWithPrivateType_ops(val p: native.Ptr[struct_structWithPrivateType]) extends AnyVal { diff --git a/tests/samples/ReuseBindings.h b/tests/samples/ReuseBindings.h index 1278216..2f6689b 100644 --- a/tests/samples/ReuseBindings.h +++ b/tests/samples/ReuseBindings.h @@ -16,3 +16,4 @@ struct usesImportedEnum { void readBook(struct book *book); myInt getMyInt(); +enumWithTypedef getEnum(); \ No newline at end of file diff --git a/tests/samples/ReuseBindings.json b/tests/samples/ReuseBindings.json index 2c166f5..70701dd 100644 --- a/tests/samples/ReuseBindings.json +++ b/tests/samples/ReuseBindings.json @@ -5,7 +5,8 @@ "names": { "struct book": "book", "struct page": "page", - "myInt": "MY_INT" + "myInt": "MY_INT", + "enumWithTypedef": "EnumWithTypedef" } } } diff --git a/tests/samples/ReuseBindings.scala b/tests/samples/ReuseBindings.scala index e1f03e7..90000a7 100644 --- a/tests/samples/ReuseBindings.scala +++ b/tests/samples/ReuseBindings.scala @@ -13,6 +13,7 @@ object ReuseBindings { def returnTypedef_point(): native.Ptr[org.scalanative.bindgen.samples.Struct.point] = native.extern def readBook(book: native.Ptr[org.scalanative.bindgen.samples.CustomNames.book]): Unit = native.extern def getMyInt(): org.scalanative.bindgen.samples.CustomNames.MY_INT = native.extern + def getEnum(): org.scalanative.bindgen.samples.CustomNames.EnumWithTypedef = native.extern } import ReuseBindings._ diff --git a/tests/samples/Struct.scala b/tests/samples/Struct.scala index 481fe29..a5545eb 100644 --- a/tests/samples/Struct.scala +++ b/tests/samples/Struct.scala @@ -7,7 +7,19 @@ import scala.scalanative.native._ @native.extern object Struct { type enum_pointIndex = native.CUnsignedInt + object enum_pointIndex { + final val X1: enum_pointIndex = 0.toUInt + final val Y1: enum_pointIndex = 1.toUInt + final val X2: enum_pointIndex = 2.toUInt + final val Y2: enum_pointIndex = 3.toUInt + } + type enum_struct_op = native.CUnsignedInt + object enum_struct_op { + final val STRUCT_SET: enum_struct_op = 0.toUInt + final val STRUCT_TEST: enum_struct_op = 1.toUInt + } + type struct_point = native.CStruct2[native.CInt, native.CInt] type point = struct_point type struct_points = native.CStruct2[struct_point, point] @@ -31,16 +43,6 @@ object Struct { import Struct._ -object StructEnums { - final val enum_pointIndex_X1: enum_pointIndex = 0.toUInt - final val enum_pointIndex_Y1: enum_pointIndex = 1.toUInt - final val enum_pointIndex_X2: enum_pointIndex = 2.toUInt - final val enum_pointIndex_Y2: enum_pointIndex = 3.toUInt - - final val enum_struct_op_STRUCT_SET: enum_struct_op = 0.toUInt - final val enum_struct_op_STRUCT_TEST: enum_struct_op = 1.toUInt -} - object StructHelpers { implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { diff --git a/tests/samples/Typedef.scala b/tests/samples/Typedef.scala index b23f5b1..255fc20 100644 --- a/tests/samples/Typedef.scala +++ b/tests/samples/Typedef.scala @@ -7,24 +7,24 @@ import scala.scalanative.native._ @native.extern object Typedef { type enum_days = native.CUnsignedInt + object enum_days { + final val MONDAY: enum_days = 0.toUInt + final val TUESDAY: enum_days = 1.toUInt + final val WEDNESDAY: enum_days = 2.toUInt + final val THURSDAY: enum_days = 3.toUInt + final val FRIDAY: enum_days = 4.toUInt + final val SATURDAY: enum_days = 5.toUInt + final val SUNDAY: enum_days = 6.toUInt + } + type enum_toggle_e = native.CUnsignedInt + object enum_toggle_e { + final val OFF: enum_toggle_e = 0.toUInt + final val ON: enum_toggle_e = 1.toUInt + } + type toggle_e = enum_toggle_e type int2int = native.CFunctionPtr1[native.CInt, native.CInt] type day2string = native.CFunctionPtr1[enum_days, native.CString] type toggle = native.CFunctionPtr1[toggle_e, Unit] } - -import Typedef._ - -object TypedefEnums { - final val enum_days_MONDAY: enum_days = 0.toUInt - final val enum_days_TUESDAY: enum_days = 1.toUInt - final val enum_days_WEDNESDAY: enum_days = 2.toUInt - final val enum_days_THURSDAY: enum_days = 3.toUInt - final val enum_days_FRIDAY: enum_days = 4.toUInt - final val enum_days_SATURDAY: enum_days = 5.toUInt - final val enum_days_SUNDAY: enum_days = 6.toUInt - - final val enum_toggle_e_OFF: enum_toggle_e = 0.toUInt - final val enum_toggle_e_ON: enum_toggle_e = 1.toUInt -} diff --git a/tests/samples/Union.scala b/tests/samples/Union.scala index a8c9246..0eb6f91 100644 --- a/tests/samples/Union.scala +++ b/tests/samples/Union.scala @@ -7,6 +7,11 @@ import scala.scalanative.native._ @native.extern object Union { type enum_union_op = native.CUnsignedInt + object enum_union_op { + final val UNION_SET: enum_union_op = 0.toUInt + final val UNION_TEST: enum_union_op = 1.toUInt + } + type struct_s = native.CStruct1[native.CInt] type union_values = native.CArray[Byte, native.Nat._8] def union_get_sizeof(): native.CInt = native.extern @@ -20,11 +25,6 @@ object Union { import Union._ -object UnionEnums { - final val enum_union_op_UNION_SET: enum_union_op = 0.toUInt - final val enum_union_op_UNION_TEST: enum_union_op = 1.toUInt -} - object UnionHelpers { implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { diff --git a/tests/samples/include/CustomNames.h b/tests/samples/include/CustomNames.h index 7955794..676984a 100644 --- a/tests/samples/include/CustomNames.h +++ b/tests/samples/include/CustomNames.h @@ -8,3 +8,4 @@ struct book { }; typedef int myInt; +typedef enum { CONST } enumWithTypedef; diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumTests.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumTests.scala index 33292f7..a4cc359 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumTests.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumTests.scala @@ -6,11 +6,11 @@ import scalanative.native._ object EnumTests extends TestSuite { val tests = Tests { 'get_WEDNESDAY - { - assert(Enum.get_WEDNESDAY() == EnumEnums.enum_days_WEDNESDAY) + assert(Enum.get_WEDNESDAY() == Enum.enum_days.WEDNESDAY) } 'check_BIG_NEG_A - { - assert(Enum.check_BIG_NEG_A(EnumEnums.enum_bigNegativeValues_BIG_NEG_A) == c"OK") + assert(Enum.check_BIG_NEG_A(Enum.enum_bigNegativeValues.BIG_NEG_A) == c"OK") } } } diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternTests.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternTests.scala index 41a1712..60d10a2 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternTests.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternTests.scala @@ -10,7 +10,7 @@ object ExternTests extends TestSuite { } 'mode - { - assert(Extern.mode == ExternEnums.enum_mode_USER) + assert(Extern.mode == Extern.enum_mode.USER) } 'semver - { diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructTests.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructTests.scala index 4ef305a..6b9a428 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructTests.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructTests.scala @@ -3,7 +3,6 @@ package org.scalanative.bindgen.samples import utest._ import scala.scalanative.native._ import org.scalanative.bindgen.samples.StructHelpers._ -import org.scalanative.bindgen.samples.StructEnums._ object StructTests extends TestSuite { val tests = Tests { @@ -38,10 +37,10 @@ object StructTests extends TestSuite { points.p1.y = 2 points.p2.x = 3 points.p2.y = 4 - assert(1 == Struct.getPoint(points, enum_pointIndex_X1)) - assert(2 == Struct.getPoint(points, enum_pointIndex_Y1)) - assert(3 == Struct.getPoint(points, enum_pointIndex_X2)) - assert(4 == Struct.getPoint(points, enum_pointIndex_Y2)) + assert(1 == Struct.getPoint(points, Struct.enum_pointIndex.X1)) + assert(2 == Struct.getPoint(points, Struct.enum_pointIndex.Y1)) + assert(3 == Struct.getPoint(points, Struct.enum_pointIndex.X2)) + assert(4 == Struct.getPoint(points, Struct.enum_pointIndex.Y2)) } } @@ -64,12 +63,12 @@ object StructTests extends TestSuite { Zone { implicit zone: Zone => val structPtr = alloc[Struct.struct_bigStruct] for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) { - Struct.struct_test_long(structPtr, enum_struct_op_STRUCT_SET, value) + Struct.struct_test_long(structPtr, Struct.enum_struct_op.STRUCT_SET, value) assert(structPtr.one == value) } for (value <- Seq(Double.MinValue, -1, 0, 1, Double.MaxValue)) { - Struct.struct_test_double(structPtr, enum_struct_op_STRUCT_SET, value) + Struct.struct_test_double(structPtr, Struct.enum_struct_op.STRUCT_SET, value) assert(structPtr.five == value) } @@ -77,7 +76,7 @@ object StructTests extends TestSuite { pointPtr.x = 5 pointPtr.y = 10 - Struct.struct_test_point(structPtr, enum_struct_op_STRUCT_SET, pointPtr) + Struct.struct_test_point(structPtr, Struct.enum_struct_op.STRUCT_SET, pointPtr) assert(structPtr.six.x == pointPtr.x) assert(structPtr.six.y == pointPtr.y) } @@ -88,19 +87,19 @@ object StructTests extends TestSuite { val structPtr = alloc[Struct.struct_bigStruct] for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) { structPtr.one = value - assert(Struct.struct_test_long(structPtr, enum_struct_op_STRUCT_TEST, value) == 1) + assert(Struct.struct_test_long(structPtr, Struct.enum_struct_op.STRUCT_TEST, value) == 1) } for (value <- Seq(Double.MinValue, -1, 0, 1, Double.MaxValue)) { structPtr.five = value - assert(Struct.struct_test_double(structPtr, enum_struct_op_STRUCT_TEST, value) == 1) + assert(Struct.struct_test_double(structPtr, Struct.enum_struct_op.STRUCT_TEST, value) == 1) } val pointPtr = alloc[Struct.point] pointPtr.x = 5 pointPtr.y = 10 structPtr.six = pointPtr - assert(Struct.struct_test_point(structPtr, enum_struct_op_STRUCT_TEST, pointPtr) == 1) + assert(Struct.struct_test_point(structPtr, Struct.enum_struct_op.STRUCT_TEST, pointPtr) == 1) } } } diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionTests.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionTests.scala index fd2c837..47f3013 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionTests.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionTests.scala @@ -15,53 +15,43 @@ object UnionTests extends TestSuite { val unionPtr = alloc[Union.union_values] for (value <- Seq(Int.MinValue, -1, 0, 1, Int.MaxValue)) { - Union.union_test_int(unionPtr, - UnionEnums.enum_union_op_UNION_SET, - value) + Union.union_test_int(unionPtr, Union.enum_union_op.UNION_SET, value) assert(!unionPtr.i == value) } for (value <- Seq(Long.MinValue, -1, 0, 1, Long.MaxValue)) { - Union.union_test_long(unionPtr, - UnionEnums.enum_union_op_UNION_SET, - value) + Union.union_test_long(unionPtr, Union.enum_union_op.UNION_SET, value) assert(!unionPtr.l == value) } - val llValues = Seq[CLongLong]( - Long.MinValue - 100, -1, 0, 1, Long.MaxValue + 100) + val llValues = + Seq[CLongLong](Long.MinValue - 100, -1, 0, 1, Long.MaxValue + 100) for (value <- llValues) { Union.union_test_long_long(unionPtr, - UnionEnums.enum_union_op_UNION_SET, + Union.enum_union_op.UNION_SET, value) assert(!unionPtr.ll == value) } for (value <- Seq(Double.MinValue, -1, 0, 1, Double.MaxValue)) { Union.union_test_double(unionPtr, - UnionEnums.enum_union_op_UNION_SET, + Union.enum_union_op.UNION_SET, value) assert(!unionPtr.d == value) } for (value <- Seq("", "bindgen")) { val s = toCString(value) - Union.union_test_string(unionPtr, - UnionEnums.enum_union_op_UNION_SET, - s) + Union.union_test_string(unionPtr, Union.enum_union_op.UNION_SET, s) assert(fromCString(!unionPtr.s) == value) } - Union.union_test_string(unionPtr, - UnionEnums.enum_union_op_UNION_SET, - null) + Union.union_test_string(unionPtr, Union.enum_union_op.UNION_SET, null) assert(!unionPtr.s == null) val struct = alloc[Union.struct_s] struct.a = 10 - Union.union_test_struct(unionPtr, - UnionEnums.enum_union_op_UNION_SET, - struct) + Union.union_test_struct(unionPtr, Union.enum_union_op.UNION_SET, struct) assert(unionPtr.structInUnion.a == 10) } } @@ -74,7 +64,7 @@ object UnionTests extends TestSuite { !unionPtr.i = value assert( Union.union_test_int(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, value) == 1) } @@ -82,17 +72,17 @@ object UnionTests extends TestSuite { !unionPtr.l = value assert( Union.union_test_long(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, value) == 1) } - val llValues = Seq[CLongLong]( - Long.MinValue - 100, -1, 0, 1, Long.MaxValue + 100) + val llValues = + Seq[CLongLong](Long.MinValue - 100, -1, 0, 1, Long.MaxValue + 100) for (value <- llValues) { !unionPtr.ll = value assert( Union.union_test_long_long(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, value) == 1) } @@ -100,7 +90,7 @@ object UnionTests extends TestSuite { !unionPtr.d = value assert( Union.union_test_double(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, value) == 1) } @@ -110,14 +100,14 @@ object UnionTests extends TestSuite { val expected = toCString(value) assert( Union.union_test_string(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, expected) == 1) } !unionPtr.s = null assert( Union.union_test_string(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, + Union.enum_union_op.UNION_TEST, null) == 1) val struct = alloc[Union.struct_s] @@ -125,8 +115,8 @@ object UnionTests extends TestSuite { unionPtr.structInUnion = struct assert( Union.union_test_struct(unionPtr, - UnionEnums.enum_union_op_UNION_TEST, - struct) == 1) + Union.enum_union_op.UNION_TEST, + struct) == 1) } } }