Update the Fortran-to-C type mapping dictionary with new mappings and return a list of successfully mapped C types. This function integrates a new mapping dictionary into an existing Fortran-to-C type mapping dictionary. It ensures that all keys are in lowercase and validates n
(f2cmap_all, new_map, c2py_map, verbose=False)
| 936 | return all_uses |
| 937 | |
| 938 | def process_f2cmap_dict(f2cmap_all, new_map, c2py_map, verbose=False): |
| 939 | """ |
| 940 | Update the Fortran-to-C type mapping dictionary with new mappings and |
| 941 | return a list of successfully mapped C types. |
| 942 | |
| 943 | This function integrates a new mapping dictionary into an existing |
| 944 | Fortran-to-C type mapping dictionary. It ensures that all keys are in |
| 945 | lowercase and validates new entries against a given C-to-Python mapping |
| 946 | dictionary. Redefinitions and invalid entries are reported with a warning. |
| 947 | |
| 948 | Parameters |
| 949 | ---------- |
| 950 | f2cmap_all : dict |
| 951 | The existing Fortran-to-C type mapping dictionary that will be updated. |
| 952 | It should be a dictionary of dictionaries where the main keys represent |
| 953 | Fortran types and the nested dictionaries map Fortran type specifiers |
| 954 | to corresponding C types. |
| 955 | |
| 956 | new_map : dict |
| 957 | A dictionary containing new type mappings to be added to `f2cmap_all`. |
| 958 | The structure should be similar to `f2cmap_all`, with keys representing |
| 959 | Fortran types and values being dictionaries of type specifiers and their |
| 960 | C type equivalents. |
| 961 | |
| 962 | c2py_map : dict |
| 963 | A dictionary used for validating the C types in `new_map`. It maps C |
| 964 | types to corresponding Python types and is used to ensure that the C |
| 965 | types specified in `new_map` are valid. |
| 966 | |
| 967 | verbose : boolean |
| 968 | A flag used to provide information about the types mapped |
| 969 | |
| 970 | Returns |
| 971 | ------- |
| 972 | tuple of (dict, list) |
| 973 | The updated Fortran-to-C type mapping dictionary and a list of |
| 974 | successfully mapped C types. |
| 975 | """ |
| 976 | f2cmap_mapped = [] |
| 977 | |
| 978 | new_map_lower = {} |
| 979 | for k, d1 in new_map.items(): |
| 980 | d1_lower = {k1.lower(): v1 for k1, v1 in d1.items()} |
| 981 | new_map_lower[k.lower()] = d1_lower |
| 982 | |
| 983 | for k, d1 in new_map_lower.items(): |
| 984 | if k not in f2cmap_all: |
| 985 | f2cmap_all[k] = {} |
| 986 | |
| 987 | for k1, v1 in d1.items(): |
| 988 | if v1 in c2py_map: |
| 989 | if k1 in f2cmap_all[k]: |
| 990 | outmess( |
| 991 | "\tWarning: redefinition of " |
| 992 | f"{{'{k}':{{'{k1}':'{f2cmap_all[k][k1]}'->'{v1}'}}}}\n" |
| 993 | ) |
| 994 | f2cmap_all[k][k1] = v1 |
| 995 | if verbose: |
searching dependent graphs…