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 | |
| 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')
| -rw-r--r-- | numpy/f2py/tests/src/crackfortran/operators.f90 | 49 | ||||
| -rw-r--r-- | numpy/f2py/tests/test_crackfortran.py | 20 |
2 files changed, 69 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 diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index fb47eb31d..e33e12d62 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -45,6 +45,26 @@ class TestPublicPrivate: assert "public" in mod["vars"]["seta"]["attrspec"] +class TestModuleProcedure(): + def test_moduleOperators(self, tmp_path): + fpath = util.getpath("tests", "src", "crackfortran", "operators.f90") + mod = crackfortran.crackfortran([str(fpath)]) + assert len(mod) == 1 + mod = mod[0] + assert "body" in mod and len(mod["body"]) == 9 + assert mod["body"][1]["name"] == "operator(.item.)" + assert "implementedby" in mod["body"][1] + assert mod["body"][1]["implementedby"] == \ + ["item_int", "item_real"] + assert mod["body"][2]["name"] == "operator(==)" + assert "implementedby" in mod["body"][2] + assert mod["body"][2]["implementedby"] == ["items_are_equal"] + assert mod["body"][3]["name"] == "assignment(=)" + assert "implementedby" in mod["body"][3] + assert mod["body"][3]["implementedby"] == \ + ["get_int", "get_real"] + + class TestExternal(util.F2PyTest): # issue gh-17859: add external attribute support sources = [util.getpath("tests", "src", "crackfortran", "gh17859.f")] |
