Skip to content

Commit

Permalink
ExEx: Track function calls in assignment lhs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Jul 12, 2023
1 parent 2808270 commit 1e9c9b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/analysis/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,13 @@ function explore_assignment!(ex::Expr, scopestate::ScopeState)::SymbolsState
global_assignees = get_global_assignees(assignees, scopestate)

# If we are _not_ assigning a global variable, then this symbol hides any global definition with that name
push!(scopestate.hiddenglobals, setdiff(assignees, global_assignees)...)
union!(scopestate.hiddenglobals, setdiff(assignees, global_assignees))
assigneesymstate = explore!(ex.args[1], scopestate)

push!(scopestate.hiddenglobals, global_assignees...)
push!(symstate.assignments, global_assignees...)
push!(symstate.references, setdiff(assigneesymstate.references, global_assignees)...)
union!(scopestate.hiddenglobals, global_assignees)
union!(symstate.assignments, global_assignees)
union!(symstate.references, setdiff(assigneesymstate.references, global_assignees))
union!(symstate.funccalls, assigneesymstate.funccalls)
filter!(!all_underscores, symstate.references) # Never record _ as a reference

return symstate
Expand Down
3 changes: 3 additions & 0 deletions test/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ Some of these @test_broken lines are commented out to prevent printing to the te
@test testee(:(x = let a = 1; a += b end), [:b], [:x], [:+], [])
@test testee(:(_ = a + 1), [:a], [], [:+], [])
@test testee(:(a = _ + 1), [], [:a], [:+], [])

@test testee(:(f()[] = 1), [], [], [:f], [])
@test testee(:(x[f()] = 1), [:x], [], [:f], [])
end
@testset "Multiple assignments" begin
# Note that using the shorthand syntax :(a = 1, b = 2) to create an expression
Expand Down

0 comments on commit 1e9c9b3

Please sign in to comment.