2
2
3
3
# Method and method table pretty-printing
4
4
5
+ const empty_sym = Symbol (" " )
6
+ function strip_gensym (sym)
7
+ if sym === Symbol (" #self#" ) || sym === Symbol (" #unused#" )
8
+ return empty_sym
9
+ end
10
+ return Symbol (replace (String (sym), r" ^(.*)#(.*#)?\d +$" => s "\1 " ))
11
+ end
12
+
5
13
function argtype_decl (env, n, @nospecialize (sig:: DataType ), i:: Int , nargs, isva:: Bool ) # -> (argname, argtype)
6
14
t = sig. parameters[i]
7
15
if i == nargs && isva && ! isvarargtype (t)
@@ -10,13 +18,13 @@ function argtype_decl(env, n, @nospecialize(sig::DataType), i::Int, nargs, isva:
10
18
if isa (n,Expr)
11
19
n = n. args[1 ] # handle n::T in arg list
12
20
end
13
- s = string (n):: String
14
- i = findfirst ( isequal ( ' # ' ), s)
15
- if i != = nothing
16
- s = s[ 1 : prevind (s, i) :: Int ]
17
- end
18
- if t === Any && ! isempty (s )
19
- return s, " "
21
+ n = strip_gensym (n)
22
+ local s
23
+ if n === empty_sym
24
+ s = " "
25
+ else
26
+ s = sprint (show_sym, n )
27
+ t === Any && return s, " "
20
28
end
21
29
if isvarargtype (t)
22
30
v1, v2 = nothing , nothing
@@ -73,8 +81,6 @@ function arg_decl_parts(m::Method, html=false)
73
81
return tv, decls, file, line
74
82
end
75
83
76
- const empty_sym = Symbol (" " )
77
-
78
84
# NOTE: second argument is deprecated and is no longer used
79
85
function kwarg_decl (m:: Method , kwtype = nothing )
80
86
mt = get_methodtable (m)
@@ -184,6 +190,15 @@ function functionloc(@nospecialize(f))
184
190
return functionloc (first (mt))
185
191
end
186
192
193
+ function sym_to_string (sym)
194
+ s = String (sym)
195
+ if endswith (s, " ..." )
196
+ return string (sprint (show_sym, Symbol (s[1 : end - 3 ])), " ..." )
197
+ else
198
+ return sprint (show_sym, sym)
199
+ end
200
+ end
201
+
187
202
function show (io:: IO , m:: Method )
188
203
tv, decls, file, line = arg_decl_parts (m)
189
204
sig = unwrap_unionall (m. sig)
@@ -193,12 +208,16 @@ function show(io::IO, m::Method)
193
208
return
194
209
end
195
210
print (io, decls[1 ][2 ], " (" )
196
- join (io, String[isempty (d[2 ]) ? d[1 ] : d[1 ]* " ::" * d[2 ] for d in decls[2 : end ]],
197
- " , " , " , " )
211
+ join (
212
+ io,
213
+ String[isempty (d[2 ]) ? d[1 ] : string (d[1 ], " ::" , d[2 ]) for d in decls[2 : end ]],
214
+ " , " ,
215
+ " , " ,
216
+ )
198
217
kwargs = kwarg_decl (m)
199
218
if ! isempty (kwargs)
200
219
print (io, " ; " )
201
- join (io, kwargs, " , " , " , " )
220
+ join (io, map (sym_to_string, kwargs) , " , " , " , " )
202
221
end
203
222
print (io, " )" )
204
223
show_method_params (io, tv)
@@ -339,12 +358,18 @@ function show(io::IO, ::MIME"text/html", m::Method)
339
358
return
340
359
end
341
360
print (io, decls[1 ][2 ], " (" )
342
- join (io, String[isempty (d[2 ]) ? d[1 ] : d[1 ]* " ::<b>" * d[2 ]* " </b>"
343
- for d in decls[2 : end ]], " , " , " , " )
361
+ join (
362
+ io,
363
+ String[
364
+ isempty (d[2 ]) ? d[1 ] : string (d[1 ], " ::<b>" , d[2 ], " </b>" ) for d in decls[2 : end ]
365
+ ],
366
+ " , " ,
367
+ " , " ,
368
+ )
344
369
kwargs = kwarg_decl (m)
345
370
if ! isempty (kwargs)
346
371
print (io, " ; <i>" )
347
- join (io, kwargs, " , " , " , " )
372
+ join (io, map (sym_to_string, kwargs) , " , " , " , " )
348
373
print (io, " </i>" )
349
374
end
350
375
print (io, " )" )
0 commit comments