From 74375b82876c81ae187e59695ad880584f9eb060 Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Thu, 28 Nov 2024 00:12:30 +0100 Subject: [PATCH] Second implementation of abstract class added --- examples/issue41_abstract_classes/Makefile | 10 ++--- .../f90wrap_myclass_factory.f90 | 2 +- .../f90wrap_myclass_impl.f90 | 38 +++++++++---------- .../itest/__init__.py | 1 + .../itest/myclass_factory.py | 4 +- .../itest/myclass_impl.py | 31 ++++++++------- .../myclass_factory.f90 | 3 ++ .../issue41_abstract_classes/myclass_impl.f90 | 6 +-- .../myclass_impl2.f90 | 27 +++++++++++++ examples/issue41_abstract_classes/run.py | 13 ++++--- 10 files changed, 84 insertions(+), 51 deletions(-) create mode 100644 examples/issue41_abstract_classes/myclass_impl2.f90 diff --git a/examples/issue41_abstract_classes/Makefile b/examples/issue41_abstract_classes/Makefile index 77695bf9..2d0d0e8f 100644 --- a/examples/issue41_abstract_classes/Makefile +++ b/examples/issue41_abstract_classes/Makefile @@ -7,14 +7,14 @@ all: wrapper test_abstract_classes.x test: wrapper $(PYTHON) run.py -test_abstract_classes.x: main.f90 myclass_base.o myclass_impl.o myclass_factory.o +test_abstract_classes.x: main.f90 myclass_base.o myclass_impl.o myclass_impl2.o myclass_factory.o $(FC) $(FCFLAGS) -o $@ $^ -wrapper: myclass_base.o myclass_impl.o myclass_factory.o - f90wrap -m itest -P myclass_base.f90 myclass_impl.f90 myclass_factory.f90 -v +wrapper: myclass_base.o myclass_impl.o myclass_impl2.o myclass_factory.o + f90wrap -m itest -P myclass_base.f90 myclass_impl.f90 myclass_impl2.f90 myclass_factory.f90 -v f2py-f90wrap --build-dir . -c -m _itest --opt="-O0 -g" \ - f90wrap_myclass_base.f90 f90wrap_myclass_impl.f90 f90wrap_myclass_factory.f90 \ - myclass_base.o myclass_impl.o myclass_factory.o + f90wrap_myclass_base.f90 f90wrap_myclass_impl.f90 f90wrap_myclass_impl2.f90 f90wrap_myclass_factory.f90 \ + myclass_base.o myclass_impl.o myclass_impl2.o myclass_factory.o %.o : %.f90 $(FC) $(FCFLAGS) -c -g -O0 $< -o $@ diff --git a/examples/issue41_abstract_classes/f90wrap_myclass_factory.f90 b/examples/issue41_abstract_classes/f90wrap_myclass_factory.f90 index 896bec19..39a192e3 100644 --- a/examples/issue41_abstract_classes/f90wrap_myclass_factory.f90 +++ b/examples/issue41_abstract_classes/f90wrap_myclass_factory.f90 @@ -1,8 +1,8 @@ ! Module myclass_factory defined in file myclass_factory.f90 subroutine f90wrap_myclass_factory__create_myclass(ret_myobject, impl_type) - use myclass_base, only: myclass_t use myclass_factory, only: create_myclass + use myclass_base, only: myclass_t implicit none type myclass_t_wrapper_type diff --git a/examples/issue41_abstract_classes/f90wrap_myclass_impl.f90 b/examples/issue41_abstract_classes/f90wrap_myclass_impl.f90 index 665e57f9..85a75c41 100644 --- a/examples/issue41_abstract_classes/f90wrap_myclass_impl.f90 +++ b/examples/issue41_abstract_classes/f90wrap_myclass_impl.f90 @@ -1,7 +1,7 @@ ! Module myclass_impl defined in file myclass_impl.f90 -subroutine f90wrap_myclass_impl__myclass_impl_finalise__binding__mycla4a60(self) - use myclass_impl, only: myclass_impl_finalise, myclass_impl_t +subroutine f90wrap_myclass_impl__myclass_impl_destroy__binding__myclas021a(self) + use myclass_impl, only: myclass_impl_destroy, myclass_impl_t implicit none type myclass_impl_t_wrapper_type @@ -14,23 +14,7 @@ subroutine f90wrap_myclass_impl__myclass_impl_finalise__binding__mycla4a60(self) integer, intent(in), dimension(2) :: self self_ptr = transfer(self, self_ptr) deallocate(self_ptr%p) -end subroutine f90wrap_myclass_impl__myclass_impl_finalise__binding__mycla4a60 - -subroutine f90wrap_myclass_impl__myclass_impl_finalise(self) - use myclass_impl, only: myclass_impl_finalise, myclass_impl_t - implicit none - - type myclass_impl_t_wrapper_type - class(myclass_impl_t), allocatable :: obj - end type myclass_impl_t_wrapper_type - type myclass_impl_t_ptr_type - type(myclass_impl_t_wrapper_type), pointer :: p => NULL() - end type myclass_impl_t_ptr_type - type(myclass_impl_t_ptr_type) :: self_ptr - integer, intent(in), dimension(2) :: self - self_ptr = transfer(self, self_ptr) - deallocate(self_ptr%p) -end subroutine f90wrap_myclass_impl__myclass_impl_finalise +end subroutine f90wrap_myclass_impl__myclass_impl_destroy__binding__myclas021a subroutine f90wrap_myclass_impl__myclass_impl_t_initialise(this) use myclass_impl, only: myclass_impl_t @@ -83,5 +67,21 @@ subroutine f90wrap_myclass_impl__get_value_impl(self, value) call get_value_impl(self=self_ptr%p%obj, value=value) end subroutine f90wrap_myclass_impl__get_value_impl +subroutine f90wrap_myclass_impl__myclass_impl_destroy(self) + use myclass_impl, only: myclass_impl_destroy, myclass_impl_t + implicit none + + type myclass_impl_t_wrapper_type + class(myclass_impl_t), allocatable :: obj + end type myclass_impl_t_wrapper_type + type myclass_impl_t_ptr_type + type(myclass_impl_t_wrapper_type), pointer :: p => NULL() + end type myclass_impl_t_ptr_type + type(myclass_impl_t_ptr_type) :: self_ptr + integer, intent(in), dimension(2) :: self + self_ptr = transfer(self, self_ptr) + call myclass_impl_destroy(self=self_ptr%p%obj) +end subroutine f90wrap_myclass_impl__myclass_impl_destroy + ! End of module myclass_impl defined in file myclass_impl.f90 diff --git a/examples/issue41_abstract_classes/itest/__init__.py b/examples/issue41_abstract_classes/itest/__init__.py index 8c185a19..a1ad5cee 100644 --- a/examples/issue41_abstract_classes/itest/__init__.py +++ b/examples/issue41_abstract_classes/itest/__init__.py @@ -5,5 +5,6 @@ import numpy import itest.myclass_factory import itest.myclass_base +import itest.myclass_impl2 import itest.myclass_impl diff --git a/examples/issue41_abstract_classes/itest/myclass_factory.py b/examples/issue41_abstract_classes/itest/myclass_factory.py index 3a48edf1..cc000bc4 100644 --- a/examples/issue41_abstract_classes/itest/myclass_factory.py +++ b/examples/issue41_abstract_classes/itest/myclass_factory.py @@ -2,7 +2,7 @@ Module myclass_factory -Defined at myclass_factory.f90 lines 1-15 +Defined at myclass_factory.f90 lines 1-18 """ from __future__ import print_function, absolute_import, division @@ -19,7 +19,7 @@ def create_myclass(impl_type): myobject = create_myclass(impl_type) - Defined at myclass_factory.f90 lines 6-15 + Defined at myclass_factory.f90 lines 7-18 Parameters ---------- diff --git a/examples/issue41_abstract_classes/itest/myclass_impl.py b/examples/issue41_abstract_classes/itest/myclass_impl.py index e857cdd8..c6766d46 100644 --- a/examples/issue41_abstract_classes/itest/myclass_impl.py +++ b/examples/issue41_abstract_classes/itest/myclass_impl.py @@ -36,22 +36,7 @@ def __del__(self): """ if self._alloc: - _itest.f90wrap_myclass_impl__myclass_impl_finalise__binding__mycla4a60(self=self._handle) - - def __del__(self): - """ - Destructor for class Myclass_Impl_T - - - Defined at myclass_impl.f90 lines 15-17 - - Parameters - ---------- - self : Myclass_Impl_T - - """ - if self._alloc: - _itest.f90wrap_myclass_impl__myclass_impl_finalise(self=self._handle) + _itest.f90wrap_myclass_impl__myclass_impl_destroy__binding__myclas021a(self=self._handle) def __init__(self, handle=None): """ @@ -115,6 +100,20 @@ def get_value_impl(self): value = _itest.f90wrap_myclass_impl__get_value_impl(self=self._handle) return value +def myclass_impl_destroy(self): + """ + myclass_impl_destroy(self) + + + Defined at myclass_impl.f90 lines 15-17 + + Parameters + ---------- + self : Myclass_Impl_T + + """ + _itest.f90wrap_myclass_impl__myclass_impl_destroy(self=self._handle) + _array_initialisers = [] _dt_array_initialisers = [] diff --git a/examples/issue41_abstract_classes/myclass_factory.f90 b/examples/issue41_abstract_classes/myclass_factory.f90 index 11b6e18f..7c04bf2e 100644 --- a/examples/issue41_abstract_classes/myclass_factory.f90 +++ b/examples/issue41_abstract_classes/myclass_factory.f90 @@ -2,6 +2,7 @@ module myclass_factory use myclass_base, only: myclass_t use myclass_impl, only: myclass_impl_t +use myclass_impl2, only: myclass_impl2_t implicit none contains @@ -14,6 +15,8 @@ function create_myclass(impl_type) result(myobject) select case(impl_type) case("impl") allocate(myclass_impl_t :: myobject) + case("impl2") + allocate(myclass_impl2_t :: myobject) case default print *, "create_field_can: Unknown implementation: ", impl_type error stop diff --git a/examples/issue41_abstract_classes/myclass_impl.f90 b/examples/issue41_abstract_classes/myclass_impl.f90 index d0539bf4..e5fea8f9 100644 --- a/examples/issue41_abstract_classes/myclass_impl.f90 +++ b/examples/issue41_abstract_classes/myclass_impl.f90 @@ -6,7 +6,7 @@ module myclass_impl type, extends(myclass_t) :: myclass_impl_t contains procedure :: get_value => get_value_impl - final :: myclass_impl_finalise + final :: myclass_impl_destroy end type myclass_impl_t contains @@ -18,10 +18,10 @@ subroutine get_value_impl(self, value) value = 1.0 end subroutine get_value_impl -subroutine myclass_impl_finalise(self) +subroutine myclass_impl_destroy(self) type(myclass_impl_t), intent(inout) :: self print *, "Finalising myclass_impl_t" -end subroutine myclass_impl_finalise +end subroutine myclass_impl_destroy end module myclass_impl diff --git a/examples/issue41_abstract_classes/myclass_impl2.f90 b/examples/issue41_abstract_classes/myclass_impl2.f90 new file mode 100644 index 00000000..6f81151c --- /dev/null +++ b/examples/issue41_abstract_classes/myclass_impl2.f90 @@ -0,0 +1,27 @@ +module myclass_impl2 + +use myclass_base, only: myclass_t +implicit none + +type, extends(myclass_t) :: myclass_impl2_t +contains + procedure :: get_value => get_value_impl2 + final :: myclass_impl2_destroy +end type myclass_impl2_t + +contains + +subroutine get_value_impl2(self, value) + class(myclass_impl2_t), intent(in) :: self + real, intent(out) :: value + + value = 2.0 +end subroutine get_value_impl2 + +subroutine myclass_impl2_destroy(self) + type(myclass_impl2_t), intent(inout) :: self + + print *, "Finalising myclass_impl2_t" +end subroutine myclass_impl2_destroy + +end module myclass_impl2 diff --git a/examples/issue41_abstract_classes/run.py b/examples/issue41_abstract_classes/run.py index 78cdc788..219315fc 100644 --- a/examples/issue41_abstract_classes/run.py +++ b/examples/issue41_abstract_classes/run.py @@ -2,7 +2,7 @@ import itest REF = 1.0 -TOL = 1.0e-14 +TOL = 1.0e-6 obj = itest.myclass_factory.create_myclass("impl") @@ -10,7 +10,10 @@ assert(abs(output-REF)