@@ -2641,16 +2641,8 @@ defmodule Macro do
26412641 # Logic operators.
26422642 defp dbg_ast_to_debuggable ( { op , _meta , [ _left , _right ] } = ast , _env )
26432643 when op in unquote ( dbg_decomposed_binary_operators ) do
2644- acc_var = unique_var ( :acc , __MODULE__ )
26452644 result_var = unique_var ( :result , __MODULE__ )
2646-
2647- [
2648- quote do
2649- unquote ( acc_var ) = [ ]
2650- unquote ( dbg_boolean_tree ( ast , acc_var , result_var ) )
2651- { :logic_op , Enum . reverse ( unquote ( acc_var ) ) , unquote ( result_var ) }
2652- end
2653- ]
2645+ dbg_boolean_tree ( ast , result_var , [ ] )
26542646 end
26552647
26562648 defp dbg_ast_to_debuggable ( { :__block__ , _meta , exprs } = ast , _env ) when exprs != [ ] do
@@ -2818,30 +2810,27 @@ defmodule Macro do
28182810 end
28192811
28202812 # This is a binary operator. We replace the left side with a recursive call to
2821- # this function to decompose it, and then execute the operation and add it to the acc.
2822- defp dbg_boolean_tree ( { op , _meta , [ left , right ] } = ast , acc_var , result_var )
2813+ # this function to decompose it
2814+ defp dbg_boolean_tree ( { op , _meta , [ left , right ] } = ast , result_var , nodes )
28232815 when op in unquote ( dbg_decomposed_binary_operators ) do
2824- replaced_left = dbg_boolean_tree ( left , acc_var , result_var )
2816+ tag = if nodes == [ ] , do: :value , else: :multi_value
28252817
2826- quote do
2827- unquote ( result_var ) = unquote ( op ) ( unquote ( replaced_left ) , unquote ( right ) )
2828-
2829- unquote ( acc_var ) = [
2830- { unquote ( escape ( ast ) ) , unquote ( result_var ) } | unquote ( acc_var )
2831- ]
2818+ node =
2819+ quote do
2820+ unquote ( result_var ) = unquote ( op ) ( unquote ( result_var ) , unquote ( right ) )
2821+ { unquote ( tag ) , unquote ( escape ( ast ) ) , unquote ( result_var ) }
2822+ end
28322823
2833- unquote ( result_var )
2834- end
2824+ dbg_boolean_tree ( left , result_var , [ node | nodes ] )
28352825 end
28362826
2837- # This is finally an expression, so we assign "result = expr", add it to the acc, and
2838- # return the result.
2839- defp dbg_boolean_tree ( ast , acc_var , result_var ) do
2840- quote do
2841- unquote ( result_var ) = unquote ( ast )
2842- unquote ( acc_var ) = [ { unquote ( escape ( ast ) ) , unquote ( result_var ) } | unquote ( acc_var ) ]
2843- unquote ( result_var )
2844- end
2827+ defp dbg_boolean_tree ( ast , result_var , nodes ) do
2828+ node =
2829+ quote do
2830+ { :multi_value , unquote ( escape ( ast ) ) , unquote ( result_var ) = unquote ( ast ) }
2831+ end
2832+
2833+ [ node | nodes ]
28452834 end
28462835
28472836 defp dbg_block ( { :__block__ , meta , exprs } , acc_var , result_var ) do
@@ -2895,15 +2884,6 @@ defmodule Macro do
28952884 { [ first_formatted | rest_formatted ] , result }
28962885 end
28972886
2898- defp dbg_format_ast_to_debug ( { :logic_op , components , value } , options ) do
2899- formatted =
2900- Enum . map ( components , fn { ast , value } ->
2901- [ dbg_format_ast ( to_string_with_colors ( ast , options ) ) , " " , inspect ( value , options ) , ?\n ]
2902- end )
2903-
2904- { formatted , value }
2905- end
2906-
29072887 defp dbg_format_ast_to_debug ( { :block , components , value } , options ) do
29082888 formatted =
29092889 [
@@ -2994,12 +2974,20 @@ defmodule Macro do
29942974 { formatted , result }
29952975 end
29962976
2977+ defp dbg_format_ast_to_debug ( { :multi_value , code_ast , value } , options ) do
2978+ { dbg_format_ast_with_value_no_newline ( code_ast , value , options ) , value }
2979+ end
2980+
29972981 defp dbg_format_ast_to_debug ( { :value , code_ast , value } , options ) do
29982982 { dbg_format_ast_with_value ( code_ast , value , options ) , value }
29992983 end
30002984
2985+ defp dbg_format_ast_with_value_no_newline ( ast , value , options ) do
2986+ [ dbg_format_ast ( to_string_with_colors ( ast , options ) ) , " " , inspect ( value , options ) ]
2987+ end
2988+
30012989 defp dbg_format_ast_with_value ( ast , value , options ) do
3002- [ dbg_format_ast ( to_string_with_colors ( ast , options ) ) , " " , inspect ( value , options ) , ?\n ]
2990+ [ dbg_format_ast_with_value_no_newline ( ast , value , options ) , ?\n ]
30032991 end
30042992
30052993 defp to_string_with_colors ( ast , options ) do
0 commit comments