Skip to content

Commit

Permalink
Merge pull request #18 from JuliaPluto/explore_macrocalls
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Mar 28, 2024
2 parents e6d75ed + a194e46 commit 87759dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/explore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,27 @@ function explore_generator!(ex::Expr, scopestate::ScopeState)
return explore!(Expr(:for, Iterators.reverse(ex.args[2:end])..., ex.args[1]), scopestate)
end

function explore_macrocall!(ex::Expr, scopestate::ScopeState)
macro_name = split_funcname(ex.args[1])
symstate = SymbolsState(macrocalls = Set{FunctionName}([macro_name]))

for arg in ex.args[begin+1:end]
macro_symstate = explore!(arg, ScopeState())
union!(symstate, SymbolsState(macrocalls = macro_symstate.macrocalls))
# explore! but only looking for macrocalls
# this is a heuristic to detect recursive macrocalls
# like `@eval @mymacro` which we couldn't
# naively detect with `macroexpand` preprocessor since
# we don't use macroexpand1
function explore_macrocalls!(ex::Expr, macrocalls)
if Meta.isexpr(ex, :macrocall)
push!(macrocalls, split_funcname(ex.args[1]))
end
for arg in ex.args
explore_macrocalls!(arg, macrocalls)
end
macrocalls
end
explore_macrocalls!(_, macrocalls) = macrocalls

return symstate

function explore_macrocall!(ex::Expr, scopestate::ScopeState)
macrocalls = Set{FunctionName}()
explore_macrocalls!(ex, macrocalls)
return SymbolsState(;macrocalls)
end

function funcname_symstate!(funcname::FunctionName, scopestate::ScopeState)::SymbolsState
Expand Down
4 changes: 4 additions & 0 deletions test/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ end
@test testee(macroexpand(Main, :(@noinline f(x) = x)), [], [], [], [
Symbol("f") => ([], [], [], [])
])
@test_nowarn test_expression_explorer(
expr=:(@mymacro a <: b = 2),
macrocalls=[Symbol("@mymacro")],
)
end
@testset "Module imports" begin
@test test_expression_explorer(
Expand Down

0 comments on commit 87759dc

Please sign in to comment.