Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure functions #317

Open
CarvFS opened this issue Aug 8, 2023 · 0 comments
Open

Pure functions #317

CarvFS opened this issue Aug 8, 2023 · 0 comments

Comments

@CarvFS
Copy link

CarvFS commented Aug 8, 2023

Hello :)

I am trying to implement a class member function whith the +pure input on shroud, i.e.:

library: Tutorial
format:
  F_filename_suffix: F90
cxx_header: tutorial.hpp

declarations:
- decl: namespace tutorial
  declarations:
  - decl: class Class1
    declarations:
    - decl: Class1() +name(new)
    - decl: ~Class1() +name(delete)
    - decl: int get_intvalue() +pure

By doing this I have the Fortran wrapper containing the prefixe pure for the function in the C interface:

   interface

        [...other functions implemented...]

        pure function c_class1_get_intvalue(self) result(SHT_rv)  bind(C, name="TUT_tutorial_Class1_get_intvalue")
            use iso_c_binding, only : C_INT
            import :: SHROUD_class1_capsule
            implicit none
            type(SHROUD_class1_capsule), intent(IN) :: self
            integer(C_INT) :: SHT_rv
        end function c_class1_get_intvalue

    end interface

But not for the function in the contains block:

    function class1_get_intvalue(obj) &
            result(SHT_rv)
        use iso_c_binding, only : C_INT
        class(class1) :: obj
        integer(C_INT) :: SHT_rv
        ! splicer begin namespace.tutorial.class.Class1.method.get_intvalue
        SHT_rv = c_class1_get_intvalue(obj%cxxmem)
        ! splicer end namespace.tutorial.class.Class1.method.get_intvalue
    end function class1_get_intvalue

I could solve this by changing from this to:

    pure function class1_get_intvalue(obj) &
            result(SHT_rv)
        use iso_c_binding, only : C_INT
        class(class1), intent(in) :: obj
        integer(C_INT) :: SHT_rv
        ! splicer begin namespace.tutorial.class.Class1.method.get_intvalue
        SHT_rv = c_class1_get_intvalue(obj%cxxmem)
        ! splicer end namespace.tutorial.class.Class1.method.get_intvalue
    end function class1_get_intvalue

Is this not supported yet or am I missing something?

Thank you very much!
Felipe Silva Carvalho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant