diff --git a/bindgen/ir/IR.cpp b/bindgen/ir/IR.cpp index ca476d1..d50ee76 100644 --- a/bindgen/ir/IR.cpp +++ b/bindgen/ir/IR.cpp @@ -171,6 +171,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) { } } + if (ir.hasHelperMethods()) { + s << "\n object implicits {\n" << ir.getHelperMethods() << " }\n"; + } + if (!isLibObjectEmpty) { s << "}\n\n"; } @@ -183,30 +187,6 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) { s << "}\n\n"; } - if (ir.hasHelperMethods()) { - s << "import " << objectName << "._\n\n"; - } - - if (ir.hasHelperMethods()) { - s << "object " << ir.libName << "Helpers {\n"; - - for (const auto &st : ir.structs) { - visitedTypes.clear(); - if (ir.shouldOutput(st, visitedTypes) && st->hasHelperMethods()) { - s << "\n" << st->generateHelperClass(ir.locationManager); - } - } - - for (const auto &u : ir.unions) { - visitedTypes.clear(); - if (ir.shouldOutput(u, visitedTypes) && u->hasHelperMethods()) { - s << "\n" << u->generateHelperClass(ir.locationManager); - } - } - - s << "}\n\n"; - } - return s; } @@ -507,3 +487,27 @@ bool IR::shouldOutputTypeDef( /* remove unused types from included files */ return locationManager.inMainFile(*typeDef->getLocation()); } + +std::string IR::getHelperMethods() const { + std::stringstream s; + std::vector> visitedTypes; + + std::string sep = ""; + + for (const auto &st : structs) { + visitedTypes.clear(); + if (shouldOutput(st, visitedTypes) && st->hasHelperMethods()) { + s << sep << st->generateHelperClass(locationManager); + sep = "\n"; + } + } + + for (const auto &u : unions) { + visitedTypes.clear(); + if (shouldOutput(u, visitedTypes) && u->hasHelperMethods()) { + s << sep << u->generateHelperClass(locationManager); + } + sep = "\n"; + } + return s.str(); +} diff --git a/bindgen/ir/IR.h b/bindgen/ir/IR.h index 2b9335d..29b8b4d 100644 --- a/bindgen/ir/IR.h +++ b/bindgen/ir/IR.h @@ -178,6 +178,8 @@ class IR { bool shouldOutputType(const std::vector> &declarations) const; + std::string getHelperMethods() const; + std::string libName; // name of the library std::string linkName; // name of the library to link with std::string objectName; // name of Scala object diff --git a/bindgen/ir/Struct.cpp b/bindgen/ir/Struct.cpp index f352c02..84abe69 100644 --- a/bindgen/ir/Struct.cpp +++ b/bindgen/ir/Struct.cpp @@ -34,7 +34,7 @@ Struct::generateHelperClass(const LocationManager &locationManager) const { assert(hasHelperMethods()); std::stringstream s; std::string type = replaceChar(getTypeName(), " ", "_"); - s << " implicit class " << type << "_ops(val p: native.Ptr[" << type + s << " implicit class " << type << "_ops(val p: native.Ptr[" << type << "])" << " extends AnyVal {\n"; if (isRepresentedAsStruct()) { @@ -42,10 +42,10 @@ Struct::generateHelperClass(const LocationManager &locationManager) const { } else { s << generateHelperClassMethodsForArrayRepresentation(locationManager); } - s << " }\n\n"; + s << " }\n"; /* makes struct instantiation easier */ - s << " def " + s << " def " << type + "()(implicit z: native.Zone): native.Ptr[" + type + "]" << " = native.alloc[" + type + "]\n"; @@ -147,7 +147,7 @@ std::string Struct::generateSetterForStructRepresentation( value = "!" + value; } std::stringstream s; - s << " def " << setter << "(value: " + parameterType + "): Unit = !p._" + s << " def " << setter << "(value: " + parameterType + "): Unit = !p._" << std::to_string(fieldIndex + 1) << " = " << value << "\n"; return s.str(); } @@ -169,7 +169,7 @@ std::string Struct::generateGetterForStructRepresentation( methodBody = "!" + methodBody; } std::stringstream s; - s << " def " << getter << ": " << returnType << " = " << methodBody + s << " def " << getter << ": " << returnType << " = " << methodBody << "\n"; return s.str(); } @@ -207,7 +207,7 @@ std::string Struct::generateSetterForArrayRepresentation( value = "!" + value; } std::stringstream s; - s << " def " << setter + s << " def " << setter << "(value: " + parameterType + "): Unit = " << castedField << " = " << value << "\n"; return s.str(); @@ -243,7 +243,7 @@ std::string Struct::generateGetterForArrayRepresentation( returnType = field->getType()->str(locationManager); } std::stringstream s; - s << " def " << getter << ": " << returnType << " = " << methodBody + s << " def " << getter << ": " << returnType << " = " << methodBody << "\n"; return s.str(); } diff --git a/bindgen/ir/Union.cpp b/bindgen/ir/Union.cpp index 3e5bf53..855dee9 100644 --- a/bindgen/ir/Union.cpp +++ b/bindgen/ir/Union.cpp @@ -22,7 +22,7 @@ Union::generateHelperClass(const LocationManager &locationManager) const { assert(hasHelperMethods()); std::stringstream s; std::string type = replaceChar(getTypeName(), " ", "_"); - s << " implicit class " << type << "_pos" + s << " implicit class " << type << "_pos" << "(val p: native.Ptr[" << type << "]) extends AnyVal {\n"; for (const auto &field : fields) { if (!field->getName().empty()) { @@ -30,7 +30,7 @@ Union::generateHelperClass(const LocationManager &locationManager) const { s << generateSetter(field, locationManager); } } - s << " }\n"; + s << " }\n"; return s.str(); } @@ -71,7 +71,7 @@ Union::generateGetter(const std::shared_ptr &field, const LocationManager &locationManager) const { std::string getter = handleReservedWords(field->getName()); std::string ftype = field->getType()->str(locationManager); - return " def " + getter + ": native.Ptr[" + ftype + + return " def " + getter + ": native.Ptr[" + ftype + "] = p.cast[native.Ptr[" + ftype + "]]\n"; } @@ -82,9 +82,9 @@ Union::generateSetter(const std::shared_ptr &field, std::string ftype = field->getType()->str(locationManager); if (isAliasForType(field->getType().get()) || isAliasForType(field->getType().get())) { - return " def " + setter + "(value: native.Ptr[" + ftype + + return " def " + setter + "(value: native.Ptr[" + ftype + "]): Unit = !p.cast[native.Ptr[" + ftype + "]] = !value\n"; } - return " def " + setter + "(value: " + ftype + + return " def " + setter + "(value: " + ftype + "): Unit = !p.cast[native.Ptr[" + ftype + "]] = value\n"; } diff --git a/tests/samples/AnonymousTypes.scala b/tests/samples/AnonymousTypes.scala index 7a9894f..3535f08 100644 --- a/tests/samples/AnonymousTypes.scala +++ b/tests/samples/AnonymousTypes.scala @@ -13,44 +13,37 @@ object AnonymousTypes { type struct_anonymous_2 = native.CStruct1[native.CInt] def foo(s: native.Ptr[struct_anonymous_0]): Unit = native.extern def bar(): native.Ptr[struct_anonymous_2] = native.extern -} - -import AnonymousTypes._ - -object AnonymousTypesHelpers { - - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def a: native.CChar = !p._1 - def a_=(value: native.CChar): Unit = !p._1 = value - } - - def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - - implicit class struct_anonymous_1_ops(val p: native.Ptr[struct_anonymous_1]) extends AnyVal { - def innerUnion: native.Ptr[union_anonymous_0] = !p._1 - def innerUnion_=(value: native.Ptr[union_anonymous_0]): Unit = !p._1 = value - } - - def struct_anonymous_1()(implicit z: native.Zone): native.Ptr[struct_anonymous_1] = native.alloc[struct_anonymous_1] - - implicit class struct_StructWithAnonymousStruct_ops(val p: native.Ptr[struct_StructWithAnonymousStruct]) extends AnyVal { - def innerStruct: native.Ptr[struct_anonymous_1] = !p._1 - def innerStruct_=(value: native.Ptr[struct_anonymous_1]): Unit = !p._1 = value - def innerEnum: native.CUnsignedInt = !p._2 - def innerEnum_=(value: native.CUnsignedInt): Unit = !p._2 = value - } - - def struct_StructWithAnonymousStruct()(implicit z: native.Zone): native.Ptr[struct_StructWithAnonymousStruct] = native.alloc[struct_StructWithAnonymousStruct] - - implicit class struct_anonymous_2_ops(val p: native.Ptr[struct_anonymous_2]) extends AnyVal { - def result: native.CInt = !p._1 - def result_=(value: native.CInt): Unit = !p._1 = value - } - - def struct_anonymous_2()(implicit z: native.Zone): native.Ptr[struct_anonymous_2] = native.alloc[struct_anonymous_2] - implicit class union_anonymous_0_pos(val p: native.Ptr[union_anonymous_0]) extends AnyVal { - def a: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] - def a_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value + object implicits { + implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { + def a: native.CChar = !p._1 + def a_=(value: native.CChar): Unit = !p._1 = value + } + def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] + + implicit class struct_anonymous_1_ops(val p: native.Ptr[struct_anonymous_1]) extends AnyVal { + def innerUnion: native.Ptr[union_anonymous_0] = !p._1 + def innerUnion_=(value: native.Ptr[union_anonymous_0]): Unit = !p._1 = value + } + def struct_anonymous_1()(implicit z: native.Zone): native.Ptr[struct_anonymous_1] = native.alloc[struct_anonymous_1] + + implicit class struct_StructWithAnonymousStruct_ops(val p: native.Ptr[struct_StructWithAnonymousStruct]) extends AnyVal { + def innerStruct: native.Ptr[struct_anonymous_1] = !p._1 + def innerStruct_=(value: native.Ptr[struct_anonymous_1]): Unit = !p._1 = value + def innerEnum: native.CUnsignedInt = !p._2 + def innerEnum_=(value: native.CUnsignedInt): Unit = !p._2 = value + } + def struct_StructWithAnonymousStruct()(implicit z: native.Zone): native.Ptr[struct_StructWithAnonymousStruct] = native.alloc[struct_StructWithAnonymousStruct] + + implicit class struct_anonymous_2_ops(val p: native.Ptr[struct_anonymous_2]) extends AnyVal { + def result: native.CInt = !p._1 + def result_=(value: native.CInt): Unit = !p._1 = value + } + def struct_anonymous_2()(implicit z: native.Zone): native.Ptr[struct_anonymous_2] = native.alloc[struct_anonymous_2] + + implicit class union_anonymous_0_pos(val p: native.Ptr[union_anonymous_0]) extends AnyVal { + def a: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] + def a_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value + } } } diff --git a/tests/samples/Cycles.scala b/tests/samples/Cycles.scala index 23c37af..c43c16b 100644 --- a/tests/samples/Cycles.scala +++ b/tests/samples/Cycles.scala @@ -22,115 +22,98 @@ object Cycles { type struct_cycleWithUnionS = native.CStruct1[native.Ptr[union_cycleWithUnionU]] type struct_FuncPointerWithValueType2 = native.CStruct1[native.CFunctionPtr0[native.CStruct0]] type struct_FuncPointerWithValueType1 = native.CStruct1[native.Ptr[struct_FuncPointerWithValueType2]] -} - -import Cycles._ - -object CyclesHelpers { - - implicit class struct_node_ops(val p: native.Ptr[struct_node]) extends AnyVal { - def value: native.CInt = !p._1 - def value_=(value: native.CInt): Unit = !p._1 = value - def next: native.Ptr[struct_node] = (!p._2).cast[native.Ptr[struct_node]] - def next_=(value: native.Ptr[struct_node]): Unit = !p._2 = value.cast[native.Ptr[Byte]] - } - - def struct_node()(implicit z: native.Zone): native.Ptr[struct_node] = native.alloc[struct_node] - - implicit class struct_a_ops(val p: native.Ptr[struct_a]) extends AnyVal { - def bb: native.Ptr[struct_b] = !p._1 - def bb_=(value: native.Ptr[struct_b]): Unit = !p._1 = value - } - - def struct_a()(implicit z: native.Zone): native.Ptr[struct_a] = native.alloc[struct_a] - - implicit class struct_b_ops(val p: native.Ptr[struct_b]) extends AnyVal { - def cc: native.Ptr[native.Ptr[struct_c]] = (!p._1).cast[native.Ptr[native.Ptr[struct_c]]] - def cc_=(value: native.Ptr[native.Ptr[struct_c]]): Unit = !p._1 = value.cast[native.Ptr[native.Ptr[Byte]]] - } - - def struct_b()(implicit z: native.Zone): native.Ptr[struct_b] = native.alloc[struct_b] - - implicit class struct_c_ops(val p: native.Ptr[struct_c]) extends AnyVal { - def aa: native.Ptr[struct_a] = p._1 - def aa_=(value: native.Ptr[struct_a]): Unit = !p._1 = !value - } - - def struct_c()(implicit z: native.Zone): native.Ptr[struct_c] = native.alloc[struct_c] - - implicit class struct_FuncPointerCycle1_ops(val p: native.Ptr[struct_FuncPointerCycle1]) extends AnyVal { - def s: native.Ptr[struct_FuncPointerCycle2] = !p._1 - def s_=(value: native.Ptr[struct_FuncPointerCycle2]): Unit = !p._1 = value - } - - def struct_FuncPointerCycle1()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle1] = native.alloc[struct_FuncPointerCycle1] - - implicit class struct_FuncPointerCycle2_ops(val p: native.Ptr[struct_FuncPointerCycle2]) extends AnyVal { - def memberFunction: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]] = (!p._1).cast[native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]] - def memberFunction_=(value: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.Ptr[Byte]]] - } - - def struct_FuncPointerCycle2()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle2] = native.alloc[struct_FuncPointerCycle2] - - implicit class struct_TypeWithTypedef2_ops(val p: native.Ptr[struct_TypeWithTypedef2]) extends AnyVal { - def s: native.Ptr[TypeWithTypedef1] = (!p._1).cast[native.Ptr[TypeWithTypedef1]] - def s_=(value: native.Ptr[TypeWithTypedef1]): Unit = !p._1 = value.cast[native.Ptr[Byte]] - } - - def struct_TypeWithTypedef2()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef2] = native.alloc[struct_TypeWithTypedef2] - - implicit class struct_TypeWithTypedef1_ops(val p: native.Ptr[struct_TypeWithTypedef1]) extends AnyVal { - def s: native.Ptr[struct_TypeWithTypedef2] = !p._1 - def s_=(value: native.Ptr[struct_TypeWithTypedef2]): Unit = !p._1 = value - } - - def struct_TypeWithTypedef1()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef1] = native.alloc[struct_TypeWithTypedef1] - - implicit class struct_TwoTypesReplaced3_ops(val p: native.Ptr[struct_TwoTypesReplaced3]) extends AnyVal { - def memberFunction: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]] = (!p._1).cast[native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]] - def memberFunction_=(value: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]): Unit = !p._1 = value.cast[native.CFunctionPtr1[native.Ptr[Byte], native.Ptr[Byte]]] - } - - def struct_TwoTypesReplaced3()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced3] = native.alloc[struct_TwoTypesReplaced3] - - implicit class struct_TwoTypesReplaced1_ops(val p: native.Ptr[struct_TwoTypesReplaced1]) extends AnyVal { - def s: native.Ptr[struct_TwoTypesReplaced2] = !p._1 - def s_=(value: native.Ptr[struct_TwoTypesReplaced2]): Unit = !p._1 = value - } - - def struct_TwoTypesReplaced1()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced1] = native.alloc[struct_TwoTypesReplaced1] - - implicit class struct_TwoTypesReplaced2_ops(val p: native.Ptr[struct_TwoTypesReplaced2]) extends AnyVal { - def s: native.Ptr[struct_TwoTypesReplaced3] = !p._1 - def s_=(value: native.Ptr[struct_TwoTypesReplaced3]): Unit = !p._1 = value - } - - def struct_TwoTypesReplaced2()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced2] = native.alloc[struct_TwoTypesReplaced2] - - implicit class struct_cycleWithUnionS_ops(val p: native.Ptr[struct_cycleWithUnionS]) extends AnyVal { - def u: native.Ptr[union_cycleWithUnionU] = !p._1 - def u_=(value: native.Ptr[union_cycleWithUnionU]): Unit = !p._1 = value - } - - def struct_cycleWithUnionS()(implicit z: native.Zone): native.Ptr[struct_cycleWithUnionS] = native.alloc[struct_cycleWithUnionS] - - implicit class struct_FuncPointerWithValueType1_ops(val p: native.Ptr[struct_FuncPointerWithValueType1]) extends AnyVal { - def s: native.Ptr[struct_FuncPointerWithValueType2] = !p._1 - def s_=(value: native.Ptr[struct_FuncPointerWithValueType2]): Unit = !p._1 = value - } - - def struct_FuncPointerWithValueType1()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType1] = native.alloc[struct_FuncPointerWithValueType1] - - implicit class struct_FuncPointerWithValueType2_ops(val p: native.Ptr[struct_FuncPointerWithValueType2]) extends AnyVal { - def memberFunction: native.CFunctionPtr0[struct_FuncPointerWithValueType1] = (!p._1).cast[native.CFunctionPtr0[struct_FuncPointerWithValueType1]] - def memberFunction_=(value: native.CFunctionPtr0[struct_FuncPointerWithValueType1]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.CStruct0]] - } - - def struct_FuncPointerWithValueType2()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType2] = native.alloc[struct_FuncPointerWithValueType2] - implicit class union_cycleWithUnionU_pos(val p: native.Ptr[union_cycleWithUnionU]) extends AnyVal { - def s: native.Ptr[native.Ptr[struct_cycleWithUnionS]] = p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] - def s_=(value: native.Ptr[struct_cycleWithUnionS]): Unit = !p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] = value + object implicits { + implicit class struct_node_ops(val p: native.Ptr[struct_node]) extends AnyVal { + def value: native.CInt = !p._1 + def value_=(value: native.CInt): Unit = !p._1 = value + def next: native.Ptr[struct_node] = (!p._2).cast[native.Ptr[struct_node]] + def next_=(value: native.Ptr[struct_node]): Unit = !p._2 = value.cast[native.Ptr[Byte]] + } + def struct_node()(implicit z: native.Zone): native.Ptr[struct_node] = native.alloc[struct_node] + + implicit class struct_a_ops(val p: native.Ptr[struct_a]) extends AnyVal { + def bb: native.Ptr[struct_b] = !p._1 + def bb_=(value: native.Ptr[struct_b]): Unit = !p._1 = value + } + def struct_a()(implicit z: native.Zone): native.Ptr[struct_a] = native.alloc[struct_a] + + implicit class struct_b_ops(val p: native.Ptr[struct_b]) extends AnyVal { + def cc: native.Ptr[native.Ptr[struct_c]] = (!p._1).cast[native.Ptr[native.Ptr[struct_c]]] + def cc_=(value: native.Ptr[native.Ptr[struct_c]]): Unit = !p._1 = value.cast[native.Ptr[native.Ptr[Byte]]] + } + def struct_b()(implicit z: native.Zone): native.Ptr[struct_b] = native.alloc[struct_b] + + implicit class struct_c_ops(val p: native.Ptr[struct_c]) extends AnyVal { + def aa: native.Ptr[struct_a] = p._1 + def aa_=(value: native.Ptr[struct_a]): Unit = !p._1 = !value + } + def struct_c()(implicit z: native.Zone): native.Ptr[struct_c] = native.alloc[struct_c] + + implicit class struct_FuncPointerCycle1_ops(val p: native.Ptr[struct_FuncPointerCycle1]) extends AnyVal { + def s: native.Ptr[struct_FuncPointerCycle2] = !p._1 + def s_=(value: native.Ptr[struct_FuncPointerCycle2]): Unit = !p._1 = value + } + def struct_FuncPointerCycle1()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle1] = native.alloc[struct_FuncPointerCycle1] + + implicit class struct_FuncPointerCycle2_ops(val p: native.Ptr[struct_FuncPointerCycle2]) extends AnyVal { + def memberFunction: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]] = (!p._1).cast[native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]] + def memberFunction_=(value: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.Ptr[Byte]]] + } + def struct_FuncPointerCycle2()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle2] = native.alloc[struct_FuncPointerCycle2] + + implicit class struct_TypeWithTypedef2_ops(val p: native.Ptr[struct_TypeWithTypedef2]) extends AnyVal { + def s: native.Ptr[TypeWithTypedef1] = (!p._1).cast[native.Ptr[TypeWithTypedef1]] + def s_=(value: native.Ptr[TypeWithTypedef1]): Unit = !p._1 = value.cast[native.Ptr[Byte]] + } + def struct_TypeWithTypedef2()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef2] = native.alloc[struct_TypeWithTypedef2] + + implicit class struct_TypeWithTypedef1_ops(val p: native.Ptr[struct_TypeWithTypedef1]) extends AnyVal { + def s: native.Ptr[struct_TypeWithTypedef2] = !p._1 + def s_=(value: native.Ptr[struct_TypeWithTypedef2]): Unit = !p._1 = value + } + def struct_TypeWithTypedef1()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef1] = native.alloc[struct_TypeWithTypedef1] + + implicit class struct_TwoTypesReplaced3_ops(val p: native.Ptr[struct_TwoTypesReplaced3]) extends AnyVal { + def memberFunction: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]] = (!p._1).cast[native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]] + def memberFunction_=(value: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]): Unit = !p._1 = value.cast[native.CFunctionPtr1[native.Ptr[Byte], native.Ptr[Byte]]] + } + def struct_TwoTypesReplaced3()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced3] = native.alloc[struct_TwoTypesReplaced3] + + implicit class struct_TwoTypesReplaced1_ops(val p: native.Ptr[struct_TwoTypesReplaced1]) extends AnyVal { + def s: native.Ptr[struct_TwoTypesReplaced2] = !p._1 + def s_=(value: native.Ptr[struct_TwoTypesReplaced2]): Unit = !p._1 = value + } + def struct_TwoTypesReplaced1()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced1] = native.alloc[struct_TwoTypesReplaced1] + + implicit class struct_TwoTypesReplaced2_ops(val p: native.Ptr[struct_TwoTypesReplaced2]) extends AnyVal { + def s: native.Ptr[struct_TwoTypesReplaced3] = !p._1 + def s_=(value: native.Ptr[struct_TwoTypesReplaced3]): Unit = !p._1 = value + } + def struct_TwoTypesReplaced2()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced2] = native.alloc[struct_TwoTypesReplaced2] + + implicit class struct_cycleWithUnionS_ops(val p: native.Ptr[struct_cycleWithUnionS]) extends AnyVal { + def u: native.Ptr[union_cycleWithUnionU] = !p._1 + def u_=(value: native.Ptr[union_cycleWithUnionU]): Unit = !p._1 = value + } + def struct_cycleWithUnionS()(implicit z: native.Zone): native.Ptr[struct_cycleWithUnionS] = native.alloc[struct_cycleWithUnionS] + + implicit class struct_FuncPointerWithValueType1_ops(val p: native.Ptr[struct_FuncPointerWithValueType1]) extends AnyVal { + def s: native.Ptr[struct_FuncPointerWithValueType2] = !p._1 + def s_=(value: native.Ptr[struct_FuncPointerWithValueType2]): Unit = !p._1 = value + } + def struct_FuncPointerWithValueType1()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType1] = native.alloc[struct_FuncPointerWithValueType1] + + implicit class struct_FuncPointerWithValueType2_ops(val p: native.Ptr[struct_FuncPointerWithValueType2]) extends AnyVal { + def memberFunction: native.CFunctionPtr0[struct_FuncPointerWithValueType1] = (!p._1).cast[native.CFunctionPtr0[struct_FuncPointerWithValueType1]] + def memberFunction_=(value: native.CFunctionPtr0[struct_FuncPointerWithValueType1]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.CStruct0]] + } + def struct_FuncPointerWithValueType2()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType2] = native.alloc[struct_FuncPointerWithValueType2] + + implicit class union_cycleWithUnionU_pos(val p: native.Ptr[union_cycleWithUnionU]) extends AnyVal { + def s: native.Ptr[native.Ptr[struct_cycleWithUnionS]] = p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] + def s_=(value: native.Ptr[struct_cycleWithUnionS]): Unit = !p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] = value + } } } diff --git a/tests/samples/Extern.scala b/tests/samples/Extern.scala index c726c41..f974ce1 100644 --- a/tests/samples/Extern.scala +++ b/tests/samples/Extern.scala @@ -17,20 +17,16 @@ object Extern { val version: native.CString = native.extern val mode: enum_mode = native.extern val semver: native.Ptr[struct_version] = native.extern -} - -import Extern._ -object ExternHelpers { - - implicit class struct_version_ops(val p: native.Ptr[struct_version]) extends AnyVal { - def major: native.CInt = !p._1 - def major_=(value: native.CInt): Unit = !p._1 = value - def minor: native.CInt = !p._2 - def minor_=(value: native.CInt): Unit = !p._2 = value - def patch: native.CInt = !p._3 - def patch_=(value: native.CInt): Unit = !p._3 = value + object implicits { + implicit class struct_version_ops(val p: native.Ptr[struct_version]) extends AnyVal { + def major: native.CInt = !p._1 + def major_=(value: native.CInt): Unit = !p._1 = value + def minor: native.CInt = !p._2 + def minor_=(value: native.CInt): Unit = !p._2 = value + def patch: native.CInt = !p._3 + def patch_=(value: native.CInt): Unit = !p._3 = value + } + def struct_version()(implicit z: native.Zone): native.Ptr[struct_version] = native.alloc[struct_version] } - - def struct_version()(implicit z: native.Zone): native.Ptr[struct_version] = native.alloc[struct_version] } diff --git a/tests/samples/Function.scala b/tests/samples/Function.scala index 1975567..d16e739 100644 --- a/tests/samples/Function.scala +++ b/tests/samples/Function.scala @@ -16,21 +16,17 @@ object Function { def anonymous_args(p0: native.CFloat, p1: native.CInt): native.CDouble = native.extern def variadic_args(a: native.CDouble, varArgs: native.CString, varArgs0: native.CVararg*): native.CDouble = native.extern def acceptsArray(p0: native.Ptr[native.CInt]): Unit = native.extern -} - -import Function._ - -object FunctionHelpers { - - implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { - def `val`: native.CInt = !p._1 - def `val_=`(value: native.CInt): Unit = !p._1 = value - } - def struct_s()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] + object implicits { + implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { + def `val`: native.CInt = !p._1 + def `val_=`(value: native.CInt): Unit = !p._1 = value + } + def struct_s()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] - implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { - def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { + def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] + def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + } } } diff --git a/tests/samples/IncludesHeader.scala b/tests/samples/IncludesHeader.scala index 90f16e9..908e0a1 100644 --- a/tests/samples/IncludesHeader.scala +++ b/tests/samples/IncludesHeader.scala @@ -18,34 +18,28 @@ object IncludesHeader { type struct_document = native.CStruct1[metadata] type struct_courseInfo = native.CStruct2[native.CString, enum_semester] def getSize(d: native.Ptr[struct_document]): size = native.extern -} - -import IncludesHeader._ - -object IncludesHeaderHelpers { - - implicit class struct_metadata_ops(val p: native.Ptr[struct_metadata]) extends AnyVal { - def year: native.CUnsignedInt = !p._1 - def year_=(value: native.CUnsignedInt): Unit = !p._1 = value - def publisher: native.CString = !p._2 - def publisher_=(value: native.CString): Unit = !p._2 = value - } - def struct_metadata()(implicit z: native.Zone): native.Ptr[struct_metadata] = native.alloc[struct_metadata] - - implicit class struct_document_ops(val p: native.Ptr[struct_document]) extends AnyVal { - def m: native.Ptr[metadata] = p._1 - def m_=(value: native.Ptr[metadata]): Unit = !p._1 = !value + object implicits { + implicit class struct_metadata_ops(val p: native.Ptr[struct_metadata]) extends AnyVal { + def year: native.CUnsignedInt = !p._1 + def year_=(value: native.CUnsignedInt): Unit = !p._1 = value + def publisher: native.CString = !p._2 + def publisher_=(value: native.CString): Unit = !p._2 = value + } + def struct_metadata()(implicit z: native.Zone): native.Ptr[struct_metadata] = native.alloc[struct_metadata] + + implicit class struct_document_ops(val p: native.Ptr[struct_document]) extends AnyVal { + def m: native.Ptr[metadata] = p._1 + def m_=(value: native.Ptr[metadata]): Unit = !p._1 = !value + } + def struct_document()(implicit z: native.Zone): native.Ptr[struct_document] = native.alloc[struct_document] + + implicit class struct_courseInfo_ops(val p: native.Ptr[struct_courseInfo]) extends AnyVal { + def name: native.CString = !p._1 + def name_=(value: native.CString): Unit = !p._1 = value + def s: enum_semester = !p._2 + def s_=(value: enum_semester): Unit = !p._2 = value + } + def struct_courseInfo()(implicit z: native.Zone): native.Ptr[struct_courseInfo] = native.alloc[struct_courseInfo] } - - def struct_document()(implicit z: native.Zone): native.Ptr[struct_document] = native.alloc[struct_document] - - implicit class struct_courseInfo_ops(val p: native.Ptr[struct_courseInfo]) extends AnyVal { - def name: native.CString = !p._1 - def name_=(value: native.CString): Unit = !p._1 = value - def s: enum_semester = !p._2 - def s_=(value: enum_semester): Unit = !p._2 = value - } - - def struct_courseInfo()(implicit z: native.Zone): native.Ptr[struct_courseInfo] = native.alloc[struct_courseInfo] } diff --git a/tests/samples/OpaqueTypes.scala b/tests/samples/OpaqueTypes.scala index 03607e9..c5363e6 100644 --- a/tests/samples/OpaqueTypes.scala +++ b/tests/samples/OpaqueTypes.scala @@ -27,46 +27,40 @@ object OpaqueTypes { def fun(): native.Ptr[native.Ptr[undefinedUnion]] = native.extern def returnPointerToAliasOfUndefinedStruct(): native.Ptr[aliasForUndefinedStruct] = native.extern def usePointerToUndefinedIncludedStruct(p0: native.Ptr[undefinedIncludedStruct]): Unit = native.extern -} - -import OpaqueTypes._ - -object OpaqueTypesHelpers { - - implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { - def point1: native.Ptr[struct_point] = !p._1 - def point1_=(value: native.Ptr[struct_point]): Unit = !p._1 = value - def point2: native.Ptr[struct_point] = !p._2 - def point2_=(value: native.Ptr[struct_point]): Unit = !p._2 = value - } - def struct_points()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] + object implicits { + implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { + def point1: native.Ptr[struct_point] = !p._1 + def point1_=(value: native.Ptr[struct_point]): Unit = !p._1 = value + def point2: native.Ptr[struct_point] = !p._2 + def point2_=(value: native.Ptr[struct_point]): Unit = !p._2 = value + } + def struct_points()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] - implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { - def x: native.CInt = !p._1 - def x_=(value: native.CInt): Unit = !p._1 = value - def y: native.CInt = !p._2 - def y_=(value: native.CInt): Unit = !p._2 = value - } - - def struct_point()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] + implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { + def x: native.CInt = !p._1 + def x_=(value: native.CInt): Unit = !p._1 = value + def y: native.CInt = !p._2 + def y_=(value: native.CInt): Unit = !p._2 = value + } + def struct_point()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] - implicit class struct_structWithPointerToUndefinedStruct_ops(val p: native.Ptr[struct_structWithPointerToUndefinedStruct]) extends AnyVal { - def field: native.Ptr[struct_undefinedStruct] = !p._1 - def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p._1 = value - } + implicit class struct_structWithPointerToUndefinedStruct_ops(val p: native.Ptr[struct_structWithPointerToUndefinedStruct]) extends AnyVal { + def field: native.Ptr[struct_undefinedStruct] = !p._1 + def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p._1 = value + } + def struct_structWithPointerToUndefinedStruct()(implicit z: native.Zone): native.Ptr[struct_structWithPointerToUndefinedStruct] = native.alloc[struct_structWithPointerToUndefinedStruct] - def struct_structWithPointerToUndefinedStruct()(implicit z: native.Zone): native.Ptr[struct_structWithPointerToUndefinedStruct] = native.alloc[struct_structWithPointerToUndefinedStruct] - - implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { - def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value - def f: native.Ptr[native.CFloat] = p.cast[native.Ptr[native.CFloat]] - def f_=(value: native.CFloat): Unit = !p.cast[native.Ptr[native.CFloat]] = value - } + implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { + def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] + def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + def f: native.Ptr[native.CFloat] = p.cast[native.Ptr[native.CFloat]] + def f_=(value: native.CFloat): Unit = !p.cast[native.Ptr[native.CFloat]] = value + } - implicit class union_unionWithPointerToUndefinedStruct_pos(val p: native.Ptr[union_unionWithPointerToUndefinedStruct]) extends AnyVal { - def field: native.Ptr[native.Ptr[struct_undefinedStruct]] = p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] - def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] = value + implicit class union_unionWithPointerToUndefinedStruct_pos(val p: native.Ptr[union_unionWithPointerToUndefinedStruct]) extends AnyVal { + def field: native.Ptr[native.Ptr[struct_undefinedStruct]] = p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] + def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] = value + } } } diff --git a/tests/samples/PrivateMembers.scala b/tests/samples/PrivateMembers.scala index c5634b2..cc0c4f1 100644 --- a/tests/samples/PrivateMembers.scala +++ b/tests/samples/PrivateMembers.scala @@ -38,44 +38,37 @@ object PrivateMembers { def usesPrivateUnion(p0: native.Ptr[union___unionWithPrivateName]): Unit = native.extern def usesPrivateStruct(p0: native.Ptr[struct_structWithPrivateType], p1: native.Ptr[struct_normalStruct]): Unit = native.extern def usesPrivateEnum(p0: native.Ptr[enum___privateEnum]): Unit = native.extern -} - -import PrivateMembers._ - -object PrivateMembersHelpers { - - implicit class struct_structWithPrivateType_ops(val p: native.Ptr[struct_structWithPrivateType]) extends AnyVal { - def field1: native.CInt = !p._1 - def field1_=(value: native.CInt): Unit = !p._1 = value - def field2: __private_type = !p._2 - def field2_=(value: __private_type): Unit = !p._2 = value - } - - def struct_structWithPrivateType()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateType] = native.alloc[struct_structWithPrivateType] - - implicit class struct_structWithPrivateStruct_ops(val p: native.Ptr[struct_structWithPrivateStruct]) extends AnyVal { - def s: native.Ptr[struct_structWithPrivateType] = !p._1 - def s_=(value: native.Ptr[struct_structWithPrivateType]): Unit = !p._1 = value - } - - def struct_structWithPrivateStruct()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateStruct] = native.alloc[struct_structWithPrivateStruct] - - implicit class struct_normalStruct_ops(val p: native.Ptr[struct_normalStruct]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value - } - - def struct_normalStruct()(implicit z: native.Zone): native.Ptr[struct_normalStruct] = native.alloc[struct_normalStruct] - - implicit class struct_privateStructWithTypedef_ops(val p: native.Ptr[struct_privateStructWithTypedef]) extends AnyVal { - def a: native.Ptr[__private_type] = !p._1 - def a_=(value: native.Ptr[__private_type]): Unit = !p._1 = value - } - - def struct_privateStructWithTypedef()(implicit z: native.Zone): native.Ptr[struct_privateStructWithTypedef] = native.alloc[struct_privateStructWithTypedef] - implicit class union___unionWithPrivateName_pos(val p: native.Ptr[union___unionWithPrivateName]) extends AnyVal { - def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + object implicits { + implicit class struct_structWithPrivateType_ops(val p: native.Ptr[struct_structWithPrivateType]) extends AnyVal { + def field1: native.CInt = !p._1 + def field1_=(value: native.CInt): Unit = !p._1 = value + def field2: __private_type = !p._2 + def field2_=(value: __private_type): Unit = !p._2 = value + } + def struct_structWithPrivateType()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateType] = native.alloc[struct_structWithPrivateType] + + implicit class struct_structWithPrivateStruct_ops(val p: native.Ptr[struct_structWithPrivateStruct]) extends AnyVal { + def s: native.Ptr[struct_structWithPrivateType] = !p._1 + def s_=(value: native.Ptr[struct_structWithPrivateType]): Unit = !p._1 = value + } + def struct_structWithPrivateStruct()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateStruct] = native.alloc[struct_structWithPrivateStruct] + + implicit class struct_normalStruct_ops(val p: native.Ptr[struct_normalStruct]) extends AnyVal { + def a: native.CInt = !p._1 + def a_=(value: native.CInt): Unit = !p._1 = value + } + def struct_normalStruct()(implicit z: native.Zone): native.Ptr[struct_normalStruct] = native.alloc[struct_normalStruct] + + implicit class struct_privateStructWithTypedef_ops(val p: native.Ptr[struct_privateStructWithTypedef]) extends AnyVal { + def a: native.Ptr[__private_type] = !p._1 + def a_=(value: native.Ptr[__private_type]): Unit = !p._1 = value + } + def struct_privateStructWithTypedef()(implicit z: native.Zone): native.Ptr[struct_privateStructWithTypedef] = native.alloc[struct_privateStructWithTypedef] + + implicit class union___unionWithPrivateName_pos(val p: native.Ptr[union___unionWithPrivateName]) extends AnyVal { + def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] + def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + } } } diff --git a/tests/samples/ReservedWords.scala b/tests/samples/ReservedWords.scala index 8c0ed09..bd7bf68 100644 --- a/tests/samples/ReservedWords.scala +++ b/tests/samples/ReservedWords.scala @@ -20,45 +20,39 @@ object ReservedWords { def `with`(`sealed`: `match`, `implicit`: native.Ptr[`match`], `forSome`: native.Ptr[`lazy`]): native.Ptr[`type`] = native.extern def `implicit`(`type`: native.Ptr[`finally`]): `match` = native.extern def _1(): Unit = native.extern -} - -import ReservedWords._ - -object ReservedWordsHelpers { - - implicit class struct_object_ops(val p: native.Ptr[struct_object]) extends AnyVal { - def `yield`: `match` = !p._1 - def `yield_=`(value: `match`): Unit = !p._1 = value - def `val`: native.CInt = !p._2 - def `val_=`(value: native.CInt): Unit = !p._2 = value - } - - def struct_object()(implicit z: native.Zone): native.Ptr[struct_object] = native.alloc[struct_object] - - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def `def`: native.CChar = !p._1 - def `def_=`(value: native.CChar): Unit = !p._1 = value - def `super`: native.Ptr[`type`] = !p._2 - def `super_=`(value: native.Ptr[`type`]): Unit = !p._2 = value - } - - def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - - implicit class struct_finally_ops(val p: native.Ptr[struct_finally]) extends AnyVal { - def `val`: `def` = !p._1 - def `val_=`(value: `def`): Unit = !p._1 = value - def `finally`: native.Ptr[`lazy`] = p._2 - def `finally_=`(value: native.Ptr[`lazy`]): Unit = !p._2 = !value - } - - def struct_finally()(implicit z: native.Zone): native.Ptr[struct_finally] = native.alloc[struct_finally] - implicit class union_lazy_pos(val p: native.Ptr[union_lazy]) extends AnyVal { - def instance: native.Ptr[native.Ptr[`object`]] = p.cast[native.Ptr[native.Ptr[`object`]]] - def instance_=(value: native.Ptr[`object`]): Unit = !p.cast[native.Ptr[native.Ptr[`object`]]] = value - def `forSome`: native.Ptr[`match`] = p.cast[native.Ptr[`match`]] - def `forSome_=`(value: `match`): Unit = !p.cast[native.Ptr[`match`]] = value - def `implicit`: native.Ptr[native.Ptr[struct_anonymous_0]] = p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] - def `implicit_=`(value: native.Ptr[struct_anonymous_0]): Unit = !p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] = value + object implicits { + implicit class struct_object_ops(val p: native.Ptr[struct_object]) extends AnyVal { + def `yield`: `match` = !p._1 + def `yield_=`(value: `match`): Unit = !p._1 = value + def `val`: native.CInt = !p._2 + def `val_=`(value: native.CInt): Unit = !p._2 = value + } + def struct_object()(implicit z: native.Zone): native.Ptr[struct_object] = native.alloc[struct_object] + + implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { + def `def`: native.CChar = !p._1 + def `def_=`(value: native.CChar): Unit = !p._1 = value + def `super`: native.Ptr[`type`] = !p._2 + def `super_=`(value: native.Ptr[`type`]): Unit = !p._2 = value + } + def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] + + implicit class struct_finally_ops(val p: native.Ptr[struct_finally]) extends AnyVal { + def `val`: `def` = !p._1 + def `val_=`(value: `def`): Unit = !p._1 = value + def `finally`: native.Ptr[`lazy`] = p._2 + def `finally_=`(value: native.Ptr[`lazy`]): Unit = !p._2 = !value + } + def struct_finally()(implicit z: native.Zone): native.Ptr[struct_finally] = native.alloc[struct_finally] + + implicit class union_lazy_pos(val p: native.Ptr[union_lazy]) extends AnyVal { + def instance: native.Ptr[native.Ptr[`object`]] = p.cast[native.Ptr[native.Ptr[`object`]]] + def instance_=(value: native.Ptr[`object`]): Unit = !p.cast[native.Ptr[native.Ptr[`object`]]] = value + def `forSome`: native.Ptr[`match`] = p.cast[native.Ptr[`match`]] + def `forSome_=`(value: `match`): Unit = !p.cast[native.Ptr[`match`]] = value + def `implicit`: native.Ptr[native.Ptr[struct_anonymous_0]] = p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] + def `implicit_=`(value: native.Ptr[struct_anonymous_0]): Unit = !p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] = value + } } } diff --git a/tests/samples/ReuseBindings.scala b/tests/samples/ReuseBindings.scala index 90000a7..4260043 100644 --- a/tests/samples/ReuseBindings.scala +++ b/tests/samples/ReuseBindings.scala @@ -14,17 +14,13 @@ object ReuseBindings { 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._ -object ReuseBindingsHelpers { - - implicit class struct_usesImportedEnum_ops(val p: native.Ptr[struct_usesImportedEnum]) extends AnyVal { - def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = !p._1 - def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = !p._1 = value + object implicits { + implicit class struct_usesImportedEnum_ops(val p: native.Ptr[struct_usesImportedEnum]) extends AnyVal { + def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = !p._1 + def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = !p._1 = value + } + def struct_usesImportedEnum()(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = native.alloc[struct_usesImportedEnum] } - - def struct_usesImportedEnum()(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = native.alloc[struct_usesImportedEnum] } diff --git a/tests/samples/Struct.scala b/tests/samples/Struct.scala index a5545eb..f87e417 100644 --- a/tests/samples/Struct.scala +++ b/tests/samples/Struct.scala @@ -39,97 +39,89 @@ object Struct { def struct_test_long(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.CLong): native.CInt = native.extern def struct_test_double(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.CDouble): native.CInt = native.extern def struct_test_point(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.Ptr[struct_point]): native.CInt = native.extern -} - -import Struct._ - -object StructHelpers { - - implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { - def x: native.CInt = !p._1 - def x_=(value: native.CInt): Unit = !p._1 = value - def y: native.CInt = !p._2 - def y_=(value: native.CInt): Unit = !p._2 = value - } - - def struct_point()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] - - implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { - def p1: native.Ptr[struct_point] = p._1 - def p1_=(value: native.Ptr[struct_point]): Unit = !p._1 = !value - def p2: native.Ptr[point] = p._2 - def p2_=(value: native.Ptr[point]): Unit = !p._2 = !value - } - def struct_points()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] - - implicit class struct_bigStruct_ops(val p: native.Ptr[struct_bigStruct]) extends AnyVal { - def one: native.CLong = !p._1.cast[native.Ptr[native.CLong]] - def one_=(value: native.CLong): Unit = !p._1.cast[native.Ptr[native.CLong]] = value - def two: native.CChar = !(p._1 + 8).cast[native.Ptr[native.CChar]] - def two_=(value: native.CChar): Unit = !(p._1 + 8).cast[native.Ptr[native.CChar]] = value - def three: native.CInt = !(p._1 + 12).cast[native.Ptr[native.CInt]] - def three_=(value: native.CInt): Unit = !(p._1 + 12).cast[native.Ptr[native.CInt]] = value - def four: native.CFloat = !(p._1 + 16).cast[native.Ptr[native.CFloat]] - def four_=(value: native.CFloat): Unit = !(p._1 + 16).cast[native.Ptr[native.CFloat]] = value - def five: native.CDouble = !(p._1 + 24).cast[native.Ptr[native.CDouble]] - def five_=(value: native.CDouble): Unit = !(p._1 + 24).cast[native.Ptr[native.CDouble]] = value - def six: native.Ptr[struct_point] = (p._1 + 32).cast[native.Ptr[struct_point]] - def six_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 32).cast[native.Ptr[struct_point]] = !value - def seven: native.Ptr[struct_point] = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] - def seven_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] = value - def eight: native.CInt = !(p._1 + 48).cast[native.Ptr[native.CInt]] - def eight_=(value: native.CInt): Unit = !(p._1 + 48).cast[native.Ptr[native.CInt]] = value - def nine: native.CInt = !(p._1 + 52).cast[native.Ptr[native.CInt]] - def nine_=(value: native.CInt): Unit = !(p._1 + 52).cast[native.Ptr[native.CInt]] = value - def ten: native.CInt = !(p._1 + 56).cast[native.Ptr[native.CInt]] - def ten_=(value: native.CInt): Unit = !(p._1 + 56).cast[native.Ptr[native.CInt]] = value - def eleven: native.CInt = !(p._1 + 60).cast[native.Ptr[native.CInt]] - def eleven_=(value: native.CInt): Unit = !(p._1 + 60).cast[native.Ptr[native.CInt]] = value - def twelve: native.CInt = !(p._1 + 64).cast[native.Ptr[native.CInt]] - def twelve_=(value: native.CInt): Unit = !(p._1 + 64).cast[native.Ptr[native.CInt]] = value - def thirteen: native.CInt = !(p._1 + 68).cast[native.Ptr[native.CInt]] - def thirteen_=(value: native.CInt): Unit = !(p._1 + 68).cast[native.Ptr[native.CInt]] = value - def fourteen: native.CInt = !(p._1 + 72).cast[native.Ptr[native.CInt]] - def fourteen_=(value: native.CInt): Unit = !(p._1 + 72).cast[native.Ptr[native.CInt]] = value - def fifteen: native.CInt = !(p._1 + 76).cast[native.Ptr[native.CInt]] - def fifteen_=(value: native.CInt): Unit = !(p._1 + 76).cast[native.Ptr[native.CInt]] = value - def sixteen: native.CInt = !(p._1 + 80).cast[native.Ptr[native.CInt]] - def sixteen_=(value: native.CInt): Unit = !(p._1 + 80).cast[native.Ptr[native.CInt]] = value - def seventeen: native.CInt = !(p._1 + 84).cast[native.Ptr[native.CInt]] - def seventeen_=(value: native.CInt): Unit = !(p._1 + 84).cast[native.Ptr[native.CInt]] = value - def eighteen: native.CInt = !(p._1 + 88).cast[native.Ptr[native.CInt]] - def eighteen_=(value: native.CInt): Unit = !(p._1 + 88).cast[native.Ptr[native.CInt]] = value - def nineteen: native.CInt = !(p._1 + 92).cast[native.Ptr[native.CInt]] - def nineteen_=(value: native.CInt): Unit = !(p._1 + 92).cast[native.Ptr[native.CInt]] = value - def twenty: native.CInt = !(p._1 + 96).cast[native.Ptr[native.CInt]] - def twenty_=(value: native.CInt): Unit = !(p._1 + 96).cast[native.Ptr[native.CInt]] = value - def twentyOne: native.CInt = !(p._1 + 100).cast[native.Ptr[native.CInt]] - def twentyOne_=(value: native.CInt): Unit = !(p._1 + 100).cast[native.Ptr[native.CInt]] = value - def twentyTwo: native.CInt = !(p._1 + 104).cast[native.Ptr[native.CInt]] - def twentyTwo_=(value: native.CInt): Unit = !(p._1 + 104).cast[native.Ptr[native.CInt]] = value - def twentyThree: native.CInt = !(p._1 + 108).cast[native.Ptr[native.CInt]] - def twentyThree_=(value: native.CInt): Unit = !(p._1 + 108).cast[native.Ptr[native.CInt]] = value - } - - def struct_bigStruct()(implicit z: native.Zone): native.Ptr[struct_bigStruct] = native.alloc[struct_bigStruct] - - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def c: native.CChar = !p._1 - def c_=(value: native.CChar): Unit = !p._1 = value - def i: native.CInt = !p._2 - def i_=(value: native.CInt): Unit = !p._2 = value + object implicits { + implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { + def x: native.CInt = !p._1 + def x_=(value: native.CInt): Unit = !p._1 = value + def y: native.CInt = !p._2 + def y_=(value: native.CInt): Unit = !p._2 = value + } + def struct_point()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] + + implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { + def p1: native.Ptr[struct_point] = p._1 + def p1_=(value: native.Ptr[struct_point]): Unit = !p._1 = !value + def p2: native.Ptr[point] = p._2 + def p2_=(value: native.Ptr[point]): Unit = !p._2 = !value + } + def struct_points()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] + + implicit class struct_bigStruct_ops(val p: native.Ptr[struct_bigStruct]) extends AnyVal { + def one: native.CLong = !p._1.cast[native.Ptr[native.CLong]] + def one_=(value: native.CLong): Unit = !p._1.cast[native.Ptr[native.CLong]] = value + def two: native.CChar = !(p._1 + 8).cast[native.Ptr[native.CChar]] + def two_=(value: native.CChar): Unit = !(p._1 + 8).cast[native.Ptr[native.CChar]] = value + def three: native.CInt = !(p._1 + 12).cast[native.Ptr[native.CInt]] + def three_=(value: native.CInt): Unit = !(p._1 + 12).cast[native.Ptr[native.CInt]] = value + def four: native.CFloat = !(p._1 + 16).cast[native.Ptr[native.CFloat]] + def four_=(value: native.CFloat): Unit = !(p._1 + 16).cast[native.Ptr[native.CFloat]] = value + def five: native.CDouble = !(p._1 + 24).cast[native.Ptr[native.CDouble]] + def five_=(value: native.CDouble): Unit = !(p._1 + 24).cast[native.Ptr[native.CDouble]] = value + def six: native.Ptr[struct_point] = (p._1 + 32).cast[native.Ptr[struct_point]] + def six_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 32).cast[native.Ptr[struct_point]] = !value + def seven: native.Ptr[struct_point] = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] + def seven_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] = value + def eight: native.CInt = !(p._1 + 48).cast[native.Ptr[native.CInt]] + def eight_=(value: native.CInt): Unit = !(p._1 + 48).cast[native.Ptr[native.CInt]] = value + def nine: native.CInt = !(p._1 + 52).cast[native.Ptr[native.CInt]] + def nine_=(value: native.CInt): Unit = !(p._1 + 52).cast[native.Ptr[native.CInt]] = value + def ten: native.CInt = !(p._1 + 56).cast[native.Ptr[native.CInt]] + def ten_=(value: native.CInt): Unit = !(p._1 + 56).cast[native.Ptr[native.CInt]] = value + def eleven: native.CInt = !(p._1 + 60).cast[native.Ptr[native.CInt]] + def eleven_=(value: native.CInt): Unit = !(p._1 + 60).cast[native.Ptr[native.CInt]] = value + def twelve: native.CInt = !(p._1 + 64).cast[native.Ptr[native.CInt]] + def twelve_=(value: native.CInt): Unit = !(p._1 + 64).cast[native.Ptr[native.CInt]] = value + def thirteen: native.CInt = !(p._1 + 68).cast[native.Ptr[native.CInt]] + def thirteen_=(value: native.CInt): Unit = !(p._1 + 68).cast[native.Ptr[native.CInt]] = value + def fourteen: native.CInt = !(p._1 + 72).cast[native.Ptr[native.CInt]] + def fourteen_=(value: native.CInt): Unit = !(p._1 + 72).cast[native.Ptr[native.CInt]] = value + def fifteen: native.CInt = !(p._1 + 76).cast[native.Ptr[native.CInt]] + def fifteen_=(value: native.CInt): Unit = !(p._1 + 76).cast[native.Ptr[native.CInt]] = value + def sixteen: native.CInt = !(p._1 + 80).cast[native.Ptr[native.CInt]] + def sixteen_=(value: native.CInt): Unit = !(p._1 + 80).cast[native.Ptr[native.CInt]] = value + def seventeen: native.CInt = !(p._1 + 84).cast[native.Ptr[native.CInt]] + def seventeen_=(value: native.CInt): Unit = !(p._1 + 84).cast[native.Ptr[native.CInt]] = value + def eighteen: native.CInt = !(p._1 + 88).cast[native.Ptr[native.CInt]] + def eighteen_=(value: native.CInt): Unit = !(p._1 + 88).cast[native.Ptr[native.CInt]] = value + def nineteen: native.CInt = !(p._1 + 92).cast[native.Ptr[native.CInt]] + def nineteen_=(value: native.CInt): Unit = !(p._1 + 92).cast[native.Ptr[native.CInt]] = value + def twenty: native.CInt = !(p._1 + 96).cast[native.Ptr[native.CInt]] + def twenty_=(value: native.CInt): Unit = !(p._1 + 96).cast[native.Ptr[native.CInt]] = value + def twentyOne: native.CInt = !(p._1 + 100).cast[native.Ptr[native.CInt]] + def twentyOne_=(value: native.CInt): Unit = !(p._1 + 100).cast[native.Ptr[native.CInt]] = value + def twentyTwo: native.CInt = !(p._1 + 104).cast[native.Ptr[native.CInt]] + def twentyTwo_=(value: native.CInt): Unit = !(p._1 + 104).cast[native.Ptr[native.CInt]] = value + def twentyThree: native.CInt = !(p._1 + 108).cast[native.Ptr[native.CInt]] + def twentyThree_=(value: native.CInt): Unit = !(p._1 + 108).cast[native.Ptr[native.CInt]] = value + } + def struct_bigStruct()(implicit z: native.Zone): native.Ptr[struct_bigStruct] = native.alloc[struct_bigStruct] + + implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { + def c: native.CChar = !p._1 + def c_=(value: native.CChar): Unit = !p._1 = value + def i: native.CInt = !p._2 + def i_=(value: native.CInt): Unit = !p._2 = value + } + def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] + + implicit class struct_structWithAnonymousStruct_ops(val p: native.Ptr[struct_structWithAnonymousStruct]) extends AnyVal { + def a: native.CInt = !p._1 + def a_=(value: native.CInt): Unit = !p._1 = value + def anonymousStruct: native.Ptr[struct_anonymous_0] = p._2 + def anonymousStruct_=(value: native.Ptr[struct_anonymous_0]): Unit = !p._2 = !value + } + def struct_structWithAnonymousStruct()(implicit z: native.Zone): native.Ptr[struct_structWithAnonymousStruct] = native.alloc[struct_structWithAnonymousStruct] } - - def struct_anonymous_0()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - - implicit class struct_structWithAnonymousStruct_ops(val p: native.Ptr[struct_structWithAnonymousStruct]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value - def anonymousStruct: native.Ptr[struct_anonymous_0] = p._2 - def anonymousStruct_=(value: native.Ptr[struct_anonymous_0]): Unit = !p._2 = !value - } - - def struct_structWithAnonymousStruct()(implicit z: native.Zone): native.Ptr[struct_structWithAnonymousStruct] = native.alloc[struct_structWithAnonymousStruct] } diff --git a/tests/samples/Union.scala b/tests/samples/Union.scala index 0eb6f91..147cc3a 100644 --- a/tests/samples/Union.scala +++ b/tests/samples/Union.scala @@ -21,31 +21,27 @@ object Union { def union_test_double(v: native.Ptr[union_values], op: enum_union_op, value: native.CDouble): native.CInt = native.extern def union_test_string(v: native.Ptr[union_values], op: enum_union_op, value: native.CString): native.CInt = native.extern def union_test_struct(v: native.Ptr[union_values], op: enum_union_op, value: native.Ptr[struct_s]): native.CInt = native.extern -} - -import Union._ - -object UnionHelpers { - - implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value - } - - def struct_s()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] - implicit class union_values_pos(val p: native.Ptr[union_values]) extends AnyVal { - def l: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] - def l_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value - def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value - def ll: native.Ptr[native.CLongLong] = p.cast[native.Ptr[native.CLongLong]] - def ll_=(value: native.CLongLong): Unit = !p.cast[native.Ptr[native.CLongLong]] = value - def d: native.Ptr[native.CDouble] = p.cast[native.Ptr[native.CDouble]] - def d_=(value: native.CDouble): Unit = !p.cast[native.Ptr[native.CDouble]] = value - def s: native.Ptr[native.CString] = p.cast[native.Ptr[native.CString]] - def s_=(value: native.CString): Unit = !p.cast[native.Ptr[native.CString]] = value - def structInUnion: native.Ptr[struct_s] = p.cast[native.Ptr[struct_s]] - def structInUnion_=(value: native.Ptr[struct_s]): Unit = !p.cast[native.Ptr[struct_s]] = !value + object implicits { + implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { + def a: native.CInt = !p._1 + def a_=(value: native.CInt): Unit = !p._1 = value + } + def struct_s()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] + + implicit class union_values_pos(val p: native.Ptr[union_values]) extends AnyVal { + def l: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] + def l_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value + def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] + def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + def ll: native.Ptr[native.CLongLong] = p.cast[native.Ptr[native.CLongLong]] + def ll_=(value: native.CLongLong): Unit = !p.cast[native.Ptr[native.CLongLong]] = value + def d: native.Ptr[native.CDouble] = p.cast[native.Ptr[native.CDouble]] + def d_=(value: native.CDouble): Unit = !p.cast[native.Ptr[native.CDouble]] = value + def s: native.Ptr[native.CString] = p.cast[native.Ptr[native.CString]] + def s_=(value: native.CString): Unit = !p.cast[native.Ptr[native.CString]] = value + def structInUnion: native.Ptr[struct_s] = p.cast[native.Ptr[struct_s]] + def structInUnion_=(value: native.Ptr[struct_s]): Unit = !p.cast[native.Ptr[struct_s]] = !value + } } } 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 60d10a2..5d1b75a 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 @@ -14,7 +14,7 @@ object ExternTests extends TestSuite { } 'semver - { - import ExternHelpers._ + import Extern.implicits._ assert(Extern.semver.major == 1 && Extern.semver.minor == 2 && Extern.semver.patch == 3) } } 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 6b9a428..455ea1a 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 @@ -2,7 +2,7 @@ package org.scalanative.bindgen.samples import utest._ import scala.scalanative.native._ -import org.scalanative.bindgen.samples.StructHelpers._ +import org.scalanative.bindgen.samples.Struct.implicits._ object StructTests extends TestSuite { val tests = Tests { 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 47f3013..863facb 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 @@ -2,7 +2,7 @@ package org.scalanative.bindgen.samples import utest._ import scala.scalanative.native._ -import org.scalanative.bindgen.samples.UnionHelpers._ +import org.scalanative.bindgen.samples.Union.implicits._ object UnionTests extends TestSuite { val tests = Tests {