Skip to content

Commit

Permalink
make Base.remove_linenums! public (#52911)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter authored Jan 17, 2024
1 parent b1c4fbf commit b4f7263
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -998,27 +998,36 @@ function findmeta_block(exargs, argsmatch=args->true)
return 0, []
end

remove_linenums!(ex) = ex
function remove_linenums!(ex::Expr)
if ex.head === :block || ex.head === :quote
# remove line number expressions from metadata (not argument literal or inert) position
filter!(ex.args) do x
isa(x, Expr) && x.head === :line && return false
isa(x, LineNumberNode) && return false
return true
"""
Base.remove_linenums!(ex)
Remove all line-number metadata from expression-like object `ex`.
"""
function remove_linenums!(@nospecialize ex)
if ex isa Expr
if ex.head === :block || ex.head === :quote
# remove line number expressions from metadata (not argument literal or inert) position
filter!(ex.args) do x
isa(x, Expr) && x.head === :line && return false
isa(x, LineNumberNode) && return false
return true
end
end
for subex in ex.args
subex isa Expr && remove_linenums!(subex)
end
return ex
elseif ex isa CodeInfo
ex.codelocs .= 0
length(ex.linetable) > 1 && resize!(ex.linetable, 1)
return ex
else
return ex
end
for subex in ex.args
subex isa Expr && remove_linenums!(subex)
end
return ex
end
function remove_linenums!(src::CodeInfo)
src.codelocs .= 0
length(src.linetable) > 1 && resize!(src.linetable, 1)
return src
end

public remove_linenums!

replace_linenums!(ex, ln::LineNumberNode) = ex
function replace_linenums!(ex::Expr, ln::LineNumberNode)
if ex.head === :block || ex.head === :quote
Expand Down

0 comments on commit b4f7263

Please sign in to comment.