@@ -2641,16 +2641,8 @@ defmodule Macro do
2641
2641
# Logic operators.
2642
2642
defp dbg_ast_to_debuggable ( { op , _meta , [ _left , _right ] } = ast , _env )
2643
2643
when op in unquote ( dbg_decomposed_binary_operators ) do
2644
- acc_var = unique_var ( :acc , __MODULE__ )
2645
2644
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 , [ ] )
2654
2646
end
2655
2647
2656
2648
defp dbg_ast_to_debuggable ( { :__block__ , _meta , exprs } = ast , _env ) when exprs != [ ] do
@@ -2818,30 +2810,27 @@ defmodule Macro do
2818
2810
end
2819
2811
2820
2812
# 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 )
2823
2815
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
2825
2817
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
2832
2823
2833
- unquote ( result_var )
2834
- end
2824
+ dbg_boolean_tree ( left , result_var , [ node | nodes ] )
2835
2825
end
2836
2826
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 ]
2845
2834
end
2846
2835
2847
2836
defp dbg_block ( { :__block__ , meta , exprs } , acc_var , result_var ) do
@@ -2895,15 +2884,6 @@ defmodule Macro do
2895
2884
{ [ first_formatted | rest_formatted ] , result }
2896
2885
end
2897
2886
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
-
2907
2887
defp dbg_format_ast_to_debug ( { :block , components , value } , options ) do
2908
2888
formatted =
2909
2889
[
@@ -2994,12 +2974,20 @@ defmodule Macro do
2994
2974
{ formatted , result }
2995
2975
end
2996
2976
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
+
2997
2981
defp dbg_format_ast_to_debug ( { :value , code_ast , value } , options ) do
2998
2982
{ dbg_format_ast_with_value ( code_ast , value , options ) , value }
2999
2983
end
3000
2984
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
+
3001
2989
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 ]
3003
2991
end
3004
2992
3005
2993
defp to_string_with_colors ( ast , options ) do
0 commit comments