(block, vars, args, tab='', as_interface=False)
| 3391 | |
| 3392 | |
| 3393 | def vars2fortran(block, vars, args, tab='', as_interface=False): |
| 3394 | setmesstext(block) |
| 3395 | ret = '' |
| 3396 | nout = [] |
| 3397 | for a in args: |
| 3398 | if a in block['vars']: |
| 3399 | nout.append(a) |
| 3400 | if 'commonvars' in block: |
| 3401 | for a in block['commonvars']: |
| 3402 | if a in vars: |
| 3403 | if a not in nout: |
| 3404 | nout.append(a) |
| 3405 | else: |
| 3406 | errmess( |
| 3407 | 'vars2fortran: Confused?!: "%s" is not defined in vars.\n' % a) |
| 3408 | if 'varnames' in block: |
| 3409 | nout.extend(block['varnames']) |
| 3410 | if not as_interface: |
| 3411 | for a in list(vars.keys()): |
| 3412 | if a not in nout: |
| 3413 | nout.append(a) |
| 3414 | for a in nout: |
| 3415 | if 'depend' in vars[a]: |
| 3416 | for d in vars[a]['depend']: |
| 3417 | if d in vars and 'depend' in vars[d] and a in vars[d]['depend']: |
| 3418 | errmess( |
| 3419 | 'vars2fortran: Warning: cross-dependence between variables "%s" and "%s"\n' % (a, d)) |
| 3420 | if 'externals' in block and a in block['externals']: |
| 3421 | if isintent_callback(vars[a]): |
| 3422 | ret = '%s%sintent(callback) %s' % (ret, tab, a) |
| 3423 | ret = '%s%sexternal %s' % (ret, tab, a) |
| 3424 | if isoptional(vars[a]): |
| 3425 | ret = '%s%soptional %s' % (ret, tab, a) |
| 3426 | if a in vars and 'typespec' not in vars[a]: |
| 3427 | continue |
| 3428 | cont = 1 |
| 3429 | for b in block['body']: |
| 3430 | if a == b['name'] and b['block'] == 'function': |
| 3431 | cont = 0 |
| 3432 | break |
| 3433 | if cont: |
| 3434 | continue |
| 3435 | if a not in vars: |
| 3436 | show(vars) |
| 3437 | outmess('vars2fortran: No definition for argument "%s".\n' % a) |
| 3438 | continue |
| 3439 | if a == block['name']: |
| 3440 | if block['block'] != 'function' or block.get('result'): |
| 3441 | # 1) skip declaring a variable that name matches with |
| 3442 | # subroutine name |
| 3443 | # 2) skip declaring function when its type is |
| 3444 | # declared via `result` construction |
| 3445 | continue |
| 3446 | if 'typespec' not in vars[a]: |
| 3447 | if 'attrspec' in vars[a] and 'external' in vars[a]['attrspec']: |
| 3448 | if a in args: |
| 3449 | ret = '%s%sexternal %s' % (ret, tab, a) |
| 3450 | continue |
no test coverage detected