Determines C type
(var)
| 187 | |
| 188 | |
| 189 | def getctype(var): |
| 190 | """ |
| 191 | Determines C type |
| 192 | """ |
| 193 | ctype = 'void' |
| 194 | if isfunction(var): |
| 195 | if 'result' in var: |
| 196 | a = var['result'] |
| 197 | else: |
| 198 | a = var['name'] |
| 199 | if a in var['vars']: |
| 200 | return getctype(var['vars'][a]) |
| 201 | else: |
| 202 | errmess(f'getctype: function {a} has no return value?!\n') |
| 203 | elif issubroutine(var): |
| 204 | return ctype |
| 205 | elif ischaracter_or_characterarray(var): |
| 206 | return 'character' |
| 207 | elif isstring_or_stringarray(var): |
| 208 | return 'string' |
| 209 | elif 'typespec' in var and var['typespec'].lower() in f2cmap_all: |
| 210 | typespec = var['typespec'].lower() |
| 211 | f2cmap = f2cmap_all[typespec] |
| 212 | ctype = f2cmap[''] # default type |
| 213 | if 'kindselector' in var: |
| 214 | if '*' in var['kindselector']: |
| 215 | try: |
| 216 | ctype = f2cmap[var['kindselector']['*']] |
| 217 | except KeyError: |
| 218 | raw_typespec = var['typespec'] |
| 219 | star = var['kindselector']['*'] |
| 220 | errmess(f'getctype: "{raw_typespec} * {star}" not supported.\n') |
| 221 | elif 'kind' in var['kindselector']: |
| 222 | if typespec + 'kind' in f2cmap_all: |
| 223 | f2cmap = f2cmap_all[typespec + 'kind'] |
| 224 | try: |
| 225 | ctype = f2cmap[var['kindselector']['kind']] |
| 226 | except KeyError: |
| 227 | if typespec in f2cmap_all: |
| 228 | f2cmap = f2cmap_all[typespec] |
| 229 | try: |
| 230 | ctype = f2cmap[str(var['kindselector']['kind'])] |
| 231 | except KeyError: |
| 232 | kind = var['kindselector']['kind'] |
| 233 | errmess(f'getctype: "{typespec}({kind=})" is mapped to C ' |
| 234 | f'"{ctype}" (to override define {{{typespec!r}: ' |
| 235 | f'{{{kind!r}: "<C typespec>"}}}} ' |
| 236 | f'in {os.getcwd()}/.f2py_f2cmap file).\n') |
| 237 | elif not isexternal(var): |
| 238 | errmess(f'getctype: No C-type found in "{var}", assuming void.\n') |
| 239 | return ctype |
| 240 | |
| 241 | |
| 242 | def f2cexpr(expr): |
no test coverage detected
searching dependent graphs…