diff options
| author | Damien Caliste <dcaliste@free.fr> | 2019-11-29 09:29:21 +0100 |
|---|---|---|
| committer | Damien Caliste <dcaliste@free.fr> | 2022-01-04 09:16:59 +0100 |
| commit | 753a146a3e1b91ebe383dac7452bc6f3697fac44 (patch) | |
| tree | ff6fc96a64487824e8b990211efc2e16bb1a4bdd /numpy/f2py/tests/src | |
| parent | 20f972ce3693d7700afe51898089613ebe4b3ee5 (diff) | |
| download | numpy-753a146a3e1b91ebe383dac7452bc6f3697fac44.tar.gz | |
ENH: add support for operator() in crackfortran.
Some interface name may contains parenthesis when used
with operator, like:
interface operator(==)
module procedure my_type_equals
end interface operator(==)
Make the end part properly detected, and store also
the operator ('==' in that case) in the name.
Also implement support to list the implemented by in
any interface declaration.
Diffstat (limited to 'numpy/f2py/tests/src')
| -rw-r--r-- | numpy/f2py/tests/src/crackfortran/operators.f90 | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/numpy/f2py/tests/src/crackfortran/operators.f90 b/numpy/f2py/tests/src/crackfortran/operators.f90 new file mode 100644 index 000000000..1d060a3d2 --- /dev/null +++ b/numpy/f2py/tests/src/crackfortran/operators.f90 @@ -0,0 +1,49 @@ +module foo + type bar + character(len = 32) :: item + end type bar + interface operator(.item.) + module procedure item_int, item_real + end interface operator(.item.) + interface operator(==) + module procedure items_are_equal + end interface operator(==) + interface assignment(=) + module procedure get_int, get_real + end interface assignment(=) +contains + function item_int(val) result(elem) + integer, intent(in) :: val + type(bar) :: elem + + write(elem%item, "(I32)") val + end function item_int + + function item_real(val) result(elem) + real, intent(in) :: val + type(bar) :: elem + + write(elem%item, "(1PE32.12)") val + end function item_real + + function items_are_equal(val1, val2) result(equal) + type(bar), intent(in) :: val1, val2 + logical :: equal + + equal = (val1%item == val2%item) + end function items_are_equal + + subroutine get_real(rval, item) + real, intent(out) :: rval + type(bar), intent(in) :: item + + read(item%item, *) rval + end subroutine get_real + + subroutine get_int(rval, item) + integer, intent(out) :: rval + type(bar), intent(in) :: item + + read(item%item, *) rval + end subroutine get_int +end module foo |
