-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Definitions not attached if multiple scopes defined in the same Sourcefile
#161
Comments
Hi Rommel,
from loki import Sourcefile, Subroutine, FindVariables
from pprint import pprint
fcode_foo = """
module foo
implicit none
integer, parameter :: j = 16
contains
integer function SUM(v)
implicit none
integer, intent(in) :: v
SUM = v + 1
end function SUM
end module foo
"""
fcode_test = """
module test
use foo
implicit none
integer, parameter :: rk = selected_real_kind(12)
integer, parameter :: ik = selected_int_kind(9)
contains
subroutine calc (n, res)
integer, intent(in) :: n
real(kind=rk), intent(inout) :: res
real(kind=rk), dimension(n) :: vec
integer(kind=ik) :: i
do i = 1, n
vec(i) = 1.0_rk/(real(n - i + 1, kind=rk))
end do
do i = 1, n
res = res + SQRT(real(i, kind=rk)) + SUM(j)
end do
end subroutine calc
end module test
"""
source_foo = Sourcefile.from_source(fcode_foo)
source_test = Sourcefile.from_source(fcode_test, definitions=source_foo.definitions)
calc_subroutine = source_test['calc']
vars = FindVariables().visit(calc_subroutine.body)
pprint(vars)
I consider this a bug but one that should be fairly easy to fix, if you wanted to try that. I suspect adding a module to Line 2075 in 19fd1c4
I hope that helps and feel free to come back with follow-up questions of course! |
Sourcefile
Regarding the execution of the following code:
Actual output:
I wanted to print variables only, however, I didn't expect to REAL, SQRT, and SUM be in the list.
I'm aware that it is the current definition, though:
loki/loki/expression/expr_visitors.py
Line 169 in 19fd1c4
So, in order to obtain the true type of deferred symbol. Would a new pass or something like that be required? I would appreciate any feedback.
The text was updated successfully, but these errors were encountered: