-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix #4163, remove xdump
and simplify dump
#15707
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -899,7 +899,6 @@ export | |
utf32, | ||
warn, | ||
wstring, | ||
xdump, | ||
|
||
# random numbers | ||
AbstractRNG, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -933,99 +933,115 @@ function show(io::IO, tv::TypeVar) | |
end | ||
end | ||
|
||
# dump & xdump - structured tree representation like R's str() | ||
# - dump is for the user-facing structure | ||
# - xdump is for the internal structure | ||
# | ||
# x is the object | ||
# n is the depth of traversal in nested types (5 is the default) | ||
# indent is a character string of spaces that is incremented at | ||
# each descent. | ||
# | ||
# Package writers may overload dump for other nested types like lists | ||
# or DataFrames. If overloaded, check the nesting level (n), and if | ||
# n > 0, dump each component. Limit to the first 10 entries. When | ||
# dumping components, decrement n, and add two spaces to indent. | ||
# | ||
# Package writers should not overload xdump. | ||
function dump(io::IO, x::SimpleVector, n::Int, indent) | ||
if isempty(x) | ||
print(io, "empty SimpleVector") | ||
return | ||
end | ||
print(io, "SimpleVector") | ||
if n > 0 | ||
for i = 1:length(x) | ||
println(io) | ||
print(io, indent, " ", i, ": ") | ||
if isassigned(x,i) | ||
dump(io, x[i], n - 1, string(indent, " ")) | ||
else | ||
print(io, undef_ref_str) | ||
end | ||
end | ||
end | ||
end | ||
|
||
function xdump(fn::Function, io::IO, x, n::Int, indent) | ||
function dump(io::IO, x::ANY, n::Int, indent) | ||
T = typeof(x) | ||
print(io, T, " ") | ||
if isa(T, DataType) && nfields(T) > 0 | ||
println(io) | ||
if isa(x, Function) | ||
print(io, x, " (function of type ", T, ")") | ||
else | ||
print(io, T) | ||
end | ||
if nfields(T) > 0 | ||
if n > 0 | ||
for field in fieldnames(T) | ||
if field != symbol("") # prevents segfault if symbol is blank | ||
print(io, indent, " ", field, ": ") | ||
if isdefined(x,field) | ||
fn(io, getfield(x, field), n - 1, string(indent, " ")) | ||
else | ||
println(io, undef_ref_str) | ||
end | ||
for field in (isa(x,Tuple) ? (1:length(x)) : fieldnames(T)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably always be |
||
println(io) | ||
print(io, indent, " ", field, ": ") | ||
if isdefined(x,field) | ||
dump(io, getfield(x, field), n - 1, string(indent, " ")) | ||
else | ||
print(io, undef_ref_str) | ||
end | ||
end | ||
end | ||
else | ||
println(io, x) | ||
!isa(x,Function) && print(io, " ", x) | ||
end | ||
nothing | ||
end | ||
function xdump(fn::Function, io::IO, x::Module, n::Int, indent) | ||
print(io, Module, " ") | ||
println(io, x) | ||
end | ||
function xdump_elts(fn::Function, io::IO, x::Array{Any}, n::Int, indent, i0, i1) | ||
|
||
dump(io::IO, x::Module, n::Int, indent) = print(io, "Module ", x) | ||
|
||
function dump_elts(io::IO, x::Array, n::Int, indent, i0, i1) | ||
for i in i0:i1 | ||
print(io, indent, " ", i, ": ") | ||
if !isdefined(x,i) | ||
println(io, undef_ref_str) | ||
print(io, undef_ref_str) | ||
else | ||
fn(io, x[i], n - 1, string(indent, " ")) | ||
dump(io, x[i], n - 1, string(indent, " ")) | ||
end | ||
i < i1 && println(io) | ||
end | ||
end | ||
function xdump(fn::Function, io::IO, x::Array{Any}, n::Int, indent) | ||
println(io, "Array($(eltype(x)),$(size(x)))") | ||
if n > 0 | ||
xdump_elts(fn, io, x, n, indent, 1, (length(x) <= 10 ? length(x) : 5)) | ||
if length(x) > 10 | ||
println(io, indent, " ...") | ||
xdump_elts(fn, io, x, n, indent, length(x)-4, length(x)) | ||
|
||
function dump(io::IO, x::Array, n::Int, indent) | ||
print(io, "Array($(eltype(x)),$(size(x)))") | ||
if eltype(x) <: Number | ||
print(io, " ") | ||
show(io, x) | ||
else | ||
if n > 0 && !isempty(x) | ||
println(io) | ||
if limit_output(io) | ||
dump_elts(io, x, n, indent, 1, (length(x) <= 10 ? length(x) : 5)) | ||
if length(x) > 10 | ||
println(io) | ||
println(io, indent, " ...") | ||
dump_elts(io, x, n, indent, length(x)-4, length(x)) | ||
end | ||
else | ||
dump_elts(io, x, n, indent, 1, length(x)) | ||
end | ||
end | ||
end | ||
end | ||
xdump(fn::Function, io::IO, x::Symbol, n::Int, indent) = println(io, typeof(x), " ", x) | ||
xdump(fn::Function, io::IO, x::Function, n::Int, indent) = println(io, x) | ||
xdump(fn::Function, io::IO, x::Array, n::Int, indent) = | ||
(print(io, "Array($(eltype(x)),$(size(x))) "); | ||
show(io, x); println(io)) | ||
dump(io::IO, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x) | ||
|
||
# Types | ||
xdump(fn::Function, io::IO, x::Union, n::Int, indent) = println(io, x) | ||
function xdump(fn::Function, io::IO, x::DataType, n::Int, indent) | ||
println(io, x, "::", typeof(x), " ", " <: ", supertype(x)) | ||
fields = fieldnames(x) | ||
if n > 0 | ||
for idx in 1:min(10, length(fields)) | ||
if fields[idx] != symbol("") # prevents segfault if symbol is blank | ||
dump(io::IO, x::Union, n::Int, indent) = print(io, x) | ||
|
||
function dump(io::IO, x::DataType, n::Int, indent) | ||
print(io, x) | ||
if x !== Any | ||
print(io, " <: ", supertype(x)) | ||
end | ||
if !(x <: Tuple) | ||
fields = fieldnames(x) | ||
if n > 0 | ||
for idx in 1:length(fields) | ||
println(io) | ||
print(io, indent, " ", fields[idx], "::") | ||
if isa(x.types[idx], DataType) | ||
xdump(fn, io, fieldtype(x,idx), n - 1, string(indent, " ")) | ||
else | ||
println(io, fieldtype(x,idx)) | ||
end | ||
#if isa(x.types[idx], DataType) | ||
# xdump(fn, io, fieldtype(x,idx), n - 1, string(indent, " ")) | ||
#else | ||
print(io, fieldtype(x,idx)) | ||
#end | ||
end | ||
end | ||
if length(fields) > 10 | ||
println(io, indent, " ...") | ||
end | ||
end | ||
end | ||
|
||
# dumptype is for displaying abstract type hierarchies like Jameson | ||
# Nash's wiki page: https://github.com/JuliaLang/julia/wiki/Types-Hierarchy | ||
|
||
function dumptype(io::IO, x, n::Int, indent) | ||
function dumptype(io::IO, x::ANY, n::Int, indent) | ||
# based on Jameson Nash's examples/typetree.jl | ||
println(io, x) | ||
if n == 0 # too deeply nested | ||
|
@@ -1066,50 +1082,12 @@ end | |
|
||
# For abstract types, use _dumptype only if it's a form that will be called | ||
# interactively. | ||
xdump(fn::Function, io::IO, x::DataType) = x.abstract ? dumptype(io, x, 5, "") : xdump(fn, io, x, 5, "") | ||
xdump(fn::Function, io::IO, x::DataType, n::Int) = x.abstract ? dumptype(io, x, n, "") : xdump(fn, io, x, n, "") | ||
|
||
# defaults: | ||
xdump(fn::Function, io::IO, x) = xdump(xdump, io, x, 5, "") # default is 5 levels | ||
xdump(fn::Function, io::IO, x, n::Int) = xdump(xdump, io, x, n, "") | ||
xdump(fn::Function, io::IO, args...) = throw(ArgumentError("invalid arguments to xdump")) | ||
xdump(fn::Function, args...) = xdump(fn, STDOUT::IO, args...) | ||
xdump(io::IO, args...) = xdump(xdump, io, args...) | ||
xdump(args...) = xdump(xdump, IOContext(STDOUT::IO, :limit_output => true), args...) | ||
xdump(arg::IO) = xdump(xdump, STDOUT::IO, arg) | ||
|
||
# Here are methods specifically for dump: | ||
dump(io::IO, x, n::Int) = dump(io, x, n, "") | ||
dump(io::IO, x) = dump(io, x, 5, "") # default is 5 levels | ||
dump(io::IO, x::AbstractString, n::Int, indent) = | ||
(print(io, typeof(x), " "); | ||
show(io, x); println(io)) | ||
dump(io::IO, x, n::Int, indent) = xdump(dump, io, x, n, indent) | ||
dump(io::IO, args...) = throw(ArgumentError("invalid arguments to dump")) | ||
dump(arg::IO) = xdump(dump, STDOUT::IO, arg) | ||
dump(args...) = dump(IOContext(STDOUT::IO, :limit_output => true), args...) | ||
|
||
function dump(io::IO, x::Dict, n::Int, indent) | ||
println(io, typeof(x), " len ", length(x)) | ||
if n > 0 | ||
i = 1 | ||
for (k,v) in x | ||
print(io, indent, " ", k, ": ") | ||
dump(io, v, n - 1, string(indent, " ")) | ||
if i > 10 | ||
println(io, indent, " ...") | ||
break | ||
end | ||
i += 1 | ||
end | ||
end | ||
end | ||
dflt_io() = IOContext(STDOUT::IO, :limit_output => true) | ||
dump(io::IO, x::DataType; maxdepth=8) = (x.abstract ? dumptype : dump)(io, x, maxdepth, "") | ||
dump(x::DataType; maxdepth=8) = (x.abstract ? dumptype : dump)(dflt_io(), x, maxdepth, "") | ||
|
||
# More generic representation for common types: | ||
dump(io::IO, x::DataType, n::Int, indent) = println(io, x.name) | ||
dump(io::IO, x::DataType, n::Int) = dump(io, x, n, "") | ||
dump(io::IO, x::DataType) = dump(io, x, 5, "") | ||
dump(io::IO, x::TypeVar, n::Int, indent) = println(io, x.name) | ||
dump(io::IO, arg; maxdepth=8) = dump(io, arg, maxdepth, "") | ||
dump(arg; maxdepth=8) = dump(dflt_io(), arg, maxdepth, "") | ||
|
||
|
||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please run genstdlib and commit updates at the same time