Skip to content

Commit

Permalink
Working for types
Browse files Browse the repository at this point in the history
  • Loading branch information
krystophny committed Nov 26, 2024
1 parent 3314a4d commit 8e92105
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 95 deletions.
6 changes: 3 additions & 3 deletions examples/issue41_abstract_classes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ test: wrapper
test_abstract_classes.x: main.f90 myclass_base.o myclass_impl.o myclass_factory.o
$(FC) $(FCFLAGS) -o $@ $^

wrapper: myclass_base.o myclass_impl.o myclass_factory.o
wrapper: myclass_impl.o myclass_factory.o
f90wrap -m itest -P myclass_impl.f90 myclass_factory.f90 -v
f2py-f90wrap --build-dir . -c -m _itest --opt="-O0 -g" f90wrap_classes.f90 \
f2py-f90wrap --build-dir . -c -m _itest --opt="-O0 -g" \
f90wrap_myclass_impl.f90 f90wrap_myclass_factory.f90 \
myclass_base.o myclass_impl.o myclass_factory.o \
myclass_impl.o myclass_factory.o \
skip: myclass_impl_reference_storage myclass_impl_wrapper_t

%.o : %.f90
Expand Down
39 changes: 0 additions & 39 deletions examples/issue41_abstract_classes/f90wrap_classes.f90

This file was deleted.

17 changes: 5 additions & 12 deletions examples/issue41_abstract_classes/f90wrap_myclass_factory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
subroutine f90wrap_myclass_factory__create_myclass(ret_myobject, impl_type)
use myclass_factory, only: create_myclass
use myclass_impl, only: myclass_impl_t
use myclass_impl_reference_storage, only: myclass_impl_wrapper_t, &
myclass_impl_t_ptr_type, myclass_impl_wrapper_t_dict_t, add_reference
implicit none

type myclass_impl_t_ptr_type
type(myclass_impl_t), pointer :: p => NULL()
end type myclass_impl_t_ptr_type
type(myclass_impl_t_ptr_type) :: ret_myobject_ptr
type(myclass_impl_wrapper_t_dict_t), pointer :: reference_storage => NULL()
integer, intent(out), dimension(2) :: ret_myobject

character*(*), intent(in) :: impl_type

print *, "create_myclass: ", impl_type

allocate(ret_myobject_ptr%p)
ret_myobject_ptr%p = create_myclass(impl_type=impl_type)
ret_myobject = transfer(ret_myobject_ptr, ret_myobject)
!reference_storage = add_reference(ret_myobject)
!reference_storage%value%obj = create_myclass(impl_type)

!ret_myobject_ptr%p => reference_storage(reference_storage_size)

end subroutine f90wrap_myclass_factory__create_myclass

! End of module myclass_factory defined in file myclass_factory.f90
41 changes: 14 additions & 27 deletions examples/issue41_abstract_classes/f90wrap_myclass_impl.f90
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
! 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_t, myclass_impl_finalise
implicit none

type myclass_impl_wrapper_t
type(myclass_impl_t), allocatable :: obj
end type myclass_impl_wrapper_t
type myclass_impl_t_ptr_type
type(myclass_impl_wrapper_t), pointer :: p => NULL()
type(myclass_impl_t), 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_finalise(self=self_ptr%p)
!deallocate(self_ptr%p)
call myclass_impl_finalise(self=self_ptr%p)
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_t, myclass_impl_finalise
implicit none

type myclass_impl_wrapper_t
type(myclass_impl_t), allocatable :: obj
end type myclass_impl_wrapper_t
type myclass_impl_t_ptr_type
type(myclass_impl_wrapper_t), pointer :: p => NULL()
type(myclass_impl_t), 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)
print *, self
deallocate(self_ptr%p%obj)
!call myclass_impl_finalise(self=self_ptr%p)
deallocate(self_ptr%p)
end subroutine f90wrap_myclass_impl__myclass_impl_finalise

subroutine f90wrap_myclass_impl__myclass_impl_t_initialise(this)
use myclass_impl, only: myclass_impl_t
implicit none

type myclass_impl_wrapper_t
type(myclass_impl_t), allocatable :: obj
end type myclass_impl_wrapper_t
type myclass_impl_t_ptr_type
type(myclass_impl_wrapper_t), pointer :: p => NULL()
type(myclass_impl_t), pointer :: p => NULL()
end type myclass_impl_t_ptr_type
type(myclass_impl_t_ptr_type) :: this_ptr
integer, intent(out), dimension(2) :: this
Expand All @@ -52,34 +45,28 @@ subroutine f90wrap_myclass_impl__get_value__binding__myclass_impl_t(self, value)
use myclass_impl, only: myclass_impl_t
implicit none

type myclass_impl_wrapper_t
type(myclass_impl_t), allocatable :: obj
end type myclass_impl_wrapper_t
type myclass_impl_t_ptr_type
type(myclass_impl_wrapper_t), pointer :: p => NULL()
type(myclass_impl_t), pointer :: p => NULL()
end type myclass_impl_t_ptr_type
type(myclass_impl_t_ptr_type) :: self_ptr
integer, intent(in), dimension(2) :: self
real, intent(out) :: value
self_ptr = transfer(self, self_ptr)
call self_ptr%p%obj%get_value(value=value)
call self_ptr%p%get_value(value=value)
end subroutine f90wrap_myclass_impl__get_value__binding__myclass_impl_t

subroutine f90wrap_myclass_impl__get_value_impl(self, value)
use myclass_impl, only: myclass_impl_t, get_value_impl
use myclass_impl, only: get_value_impl, myclass_impl_t
implicit none

type myclass_impl_wrapper_t
type(myclass_impl_t), allocatable :: obj
end type myclass_impl_wrapper_t
type myclass_impl_t_ptr_type
type(myclass_impl_wrapper_t), pointer :: p => NULL()
type(myclass_impl_t), pointer :: p => NULL()
end type myclass_impl_t_ptr_type
type(myclass_impl_t_ptr_type) :: self_ptr
integer, intent(in), dimension(2) :: self
real, intent(out) :: value
self_ptr = transfer(self, self_ptr)
call get_value_impl(self=self_ptr%p%obj, value=value)
call get_value_impl(self=self_ptr%p, value=value)
end subroutine f90wrap_myclass_impl__get_value_impl

! End of module myclass_impl defined in file myclass_impl.f90
4 changes: 2 additions & 2 deletions examples/issue41_abstract_classes/itest/myclass_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module myclass_factory
Defined at myclass_factory.f90 lines 1-15
Defined at myclass_factory.f90 lines 1-14
"""
from __future__ import print_function, absolute_import, division
Expand All @@ -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 5-14
Parameters
----------
Expand Down
14 changes: 7 additions & 7 deletions examples/issue41_abstract_classes/itest/myclass_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module myclass_impl
Defined at myclass_impl.f90 lines 1-17
Defined at myclass_impl.f90 lines 1-16
"""
from __future__ import print_function, absolute_import, division
Expand All @@ -20,15 +20,15 @@ class myclass_impl_t(f90wrap.runtime.FortranDerivedType):
Type(name=myclass_impl_t)
Defined at myclass_impl.f90 lines 4-7
Defined at myclass_impl.f90 lines 3-6
"""
def __del__(self):
"""
Destructor for class Myclass_Impl_T
Defined at myclass_impl.f90 lines 15-17
Defined at myclass_impl.f90 lines 14-16
Parameters
----------
Expand All @@ -43,7 +43,7 @@ def __del__(self):
Destructor for class Myclass_Impl_T
Defined at myclass_impl.f90 lines 15-17
Defined at myclass_impl.f90 lines 14-16
Parameters
----------
Expand All @@ -58,7 +58,7 @@ def __init__(self, handle=None):
self = Myclass_Impl_T()
Defined at myclass_impl.f90 lines 4-7
Defined at myclass_impl.f90 lines 3-6
Returns
Expand All @@ -78,7 +78,7 @@ def get_value(self):
value = get_value__binding__myclass_impl_t(self)
Defined at myclass_impl.f90 lines 10-13
Defined at myclass_impl.f90 lines 9-12
Parameters
----------
Expand All @@ -101,7 +101,7 @@ def get_value_impl(self):
value = get_value_impl(self)
Defined at myclass_impl.f90 lines 10-13
Defined at myclass_impl.f90 lines 9-12
Parameters
----------
Expand Down
1 change: 0 additions & 1 deletion examples/issue41_abstract_classes/myclass_factory.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module myclass_factory

use myclass_base, only: myclass_t
use myclass_impl, only: myclass_impl_t
implicit none

Expand Down
9 changes: 5 additions & 4 deletions examples/issue41_abstract_classes/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
TOL = 1.0e-14

obj = itest.myclass_factory.create_myclass("impl")

output = obj.get_value()
assert(abs(output-REF)<TOL)
print(f"OK: {output} == {REF}")

obj2 = itest.myclass_factory.create_myclass("impl")
output2 = obj2.get_value()
assert(abs(output-REF)<TOL)
print(f"OK: {output2} == {REF}")
# obj2 = itest.myclass_factory.create_myclass("impl")
# output2 = obj2.get_value()
# assert(abs(output-REF)<TOL)
# print(f"OK: {output2} == {REF}")

0 comments on commit 8e92105

Please sign in to comment.