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