@@ -4,19 +4,24 @@ using ..UtilsModule: deprecate_varmap
44using .. OperatorEnumModule: AbstractOperatorEnum
55using .. NodeModule: AbstractExpressionNode, tree_mapreduce
66
7- function dispatch_op_name (:: Val{deg} , :: Nothing , idx):: Vector{Char} where {deg}
8- if deg == 1
9- return vcat (collect (" unary_operator[" ), collect (string (idx)), [' ]' ])
10- else
11- return vcat (collect (" binary_operator[" ), collect (string (idx)), [' ]' ])
12- end
7+ function dispatch_op_name (
8+ :: Val{deg} , :: Nothing , idx, pretty:: Bool
9+ ):: Vector{Char} where {deg}
10+ return vcat (
11+ collect (deg == 1 ? " unary_operator[" : " binary_operator[" ),
12+ collect (string (idx)),
13+ [' ]' ],
14+ )
1315end
14- function dispatch_op_name (:: Val{deg} , operators:: AbstractOperatorEnum , idx) where {deg}
15- if deg == 1
16- return collect (get_op_name (operators. unaops[idx]):: String )
16+ function dispatch_op_name (
17+ :: Val{deg} , operators:: AbstractOperatorEnum , idx, pretty:: Bool
18+ ) where {deg}
19+ op = if deg == 1
20+ operators. unaops[idx]
1721 else
18- return collect ( get_op_name ( operators. binops[idx]) :: String )
22+ operators. binops[idx]
1923 end
24+ return collect ((pretty ? get_pretty_op_name (op) : get_op_name (op)):: String )
2025end
2126
2227const OP_NAME_CACHE = (; x= Dict {UInt64,String} (), lock= Threads. SpinLock ())
@@ -47,6 +52,9 @@ function get_op_name(op::F) where {F}
4752 unlock (OP_NAME_CACHE. lock)
4853 end
4954end
55+ function get_pretty_op_name (op:: F ) where {F}
56+ return get_op_name (op)
57+ end
5058
5159@inline function strip_brackets (s:: Vector{Char} ):: Vector{Char}
5260 if first (s) == ' (' && last (s) == ' )'
@@ -145,8 +153,9 @@ function string_tree(
145153 raw:: Union{Bool,Nothing} = nothing ,
146154 varMap= nothing ,
147155):: String where {T,F1<: Function ,F2<: Function }
148- ! isnothing (raw) &&
156+ if ! isnothing (raw)
149157 Base. depwarn (" `raw` is deprecated; use `pretty` instead" , :string_tree )
158+ end
150159 pretty = @something (pretty, _not (raw), false )
151160 variable_names = deprecate_varmap (variable_names, varMap, :string_tree )
152161 raw_output = tree_mapreduce (
@@ -162,9 +171,9 @@ function string_tree(
162171 end ,
163172 let operators = operators
164173 (branch,) -> if branch. degree == 1
165- dispatch_op_name (Val (1 ), operators, branch. op):: Vector{Char}
174+ dispatch_op_name (Val (1 ), operators, branch. op, pretty ):: Vector{Char}
166175 else
167- dispatch_op_name (Val (2 ), operators, branch. op):: Vector{Char}
176+ dispatch_op_name (Val (2 ), operators, branch. op, pretty ):: Vector{Char}
168177 end
169178 end ,
170179 combine_op_with_inputs,
0 commit comments