Commit bdbb7403 authored by Daniel Nemergut's avatar Daniel Nemergut
Browse files

Added string support (I think?)

parent 0616c170
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -8,13 +8,13 @@ c_file = "cdict_fortran_api"
f_file = "cdict_fortran_interface.f90"

# Supported types, using a dict, heh...
#   nickname: [c_type, f_type, binding_type]
#   nickname: [c_type, f_type, binding_type, array]
c_types = {
    "f": ["float", "real", "c_float"],
    "d": ["double", "real", "c_double"],
    "i": ["int", "integer", "c_int"],
    "b": ["Boolean", "logical", "c_bool"],
    "p": ["void *", "type", "c_ptr"]
    "i": ["int", "integer", "c_int", False],
    "f": ["float", "real", "c_float", False],
    "d": ["double", "real", "c_double", False],
    "s": ["char *", "character", "kind=c_char", True],
    "p": ["void *", "type", "c_ptr", False]
}

# Nested depth that we can support, 3 will result in 20k+ lines of API code
@@ -50,7 +50,9 @@ def write_nest_f(file, str1, str2, str3, str4, str5, currdepth):
        nestpath2 = str2 + ", p{}".format(currdepth)
        nestpath3 = str3 + "_{}".format(nnpath)
        nestpath4 = str4 + """
            {}({}), intent(in), VALUE :: p{}""".format(typepath[1], typepath[2], currdepth)
            {}({}), intent(in){} :: p{}{}""".format(typepath[1], typepath[2],
                                                    "" if typepath[3] else ", VALUE",
                                                    currdepth, "(*)" if typepath[3] else "")
        nestpath5 = str5 + "_{}".format(nnpath)
        if currdepth < nested_depth:
            write_nest_f(file, nestpath1, nestpath2, nestpath3, nestpath4, nestpath5, currdepth + 1)
@@ -279,10 +281,16 @@ module libcdict_m
        subroutine f_cdict_set_{}_{}(cdict, key, value) bind(c,name="f_cdict_set_{}_{}")
            use, intrinsic :: iso_c_binding
            type(c_ptr), intent(in), VALUE :: cdict
            {}({}), intent(in), VALUE :: key
            {}({}), intent(in), VALUE :: value
            {}({}), intent(in){} :: key{}
            {}({}), intent(in){} :: value{}
        end subroutine f_cdict_set_{}_{}
""".format(nnkey, nnval, nnkey, nnval, typekey[1], typekey[2], typeval[1], typeval[2], nnkey, nnval))
""".format(nnkey, nnval, nnkey, nnval, typekey[1], typekey[2],
                "" if typekey[3] else ", VALUE",
                "(*)" if typekey[3] else "",
                typeval[1], typeval[2],
                "" if typeval[3] else ", VALUE",
                "(*)" if typeval[3] else "",
                nnkey, nnval))

    f.write("""    end interface CDict_set
    
@@ -298,7 +306,9 @@ module libcdict_m
        nestkey4 = """")
            use, intrinsic :: iso_c_binding
            type(c_ptr), intent(in), VALUE :: cdict
            {}({}), intent(in), VALUE :: key""".format(typekey[1], typekey[2])
            {}({}), intent(in){} :: key{}""".format(typekey[1], typekey[2],
                                                    "" if typekey[3] else ", VALUE",
                                                    "(*)" if typekey[3] else "")
        nestkey5 = """
        end subroutine f_cdict_nest_{}""".format(nnkey)

@@ -307,7 +317,9 @@ module libcdict_m
            nestval2 = nestkey2 + ", value"
            nestval3 = nestkey3 + "_{}".format(nnval)
            nestval4 = nestkey4 + """
            {}({}), intent(in), VALUE :: value""".format(typeval[1], typeval[2])
            {}({}), intent(in){} :: value{}""".format(typeval[1], typeval[2],
                                                      "" if typeval[3] else ", VALUE",
                                                      "(*)" if typeval[3] else "")
            nestval5 = nestkey5 + "_{}".format(nnval)
            write_nest_f(f, nestval1, nestval2, nestval3, nestval4, nestval5, 1)