diff --git a/lib/postgrex/extensions/array.ex b/lib/postgrex/extensions/array.ex index b180b9aa..92d3a959 100644 --- a/lib/postgrex/extensions/array.ex +++ b/lib/postgrex/extensions/array.ex @@ -28,15 +28,15 @@ defmodule Postgrex.Extensions.Array do def decode(_) do quote location: :keep do - <>, [oid], [type], mod -> + <>, [oid], [type] -> <> = binary # decode_list/2 defined by TypeModule type = case type do - {extension, sub_oids, sub_types} -> {extension, sub_oids, sub_types, mod} - extension -> {extension, mod} + {extension, sub_oids, sub_types} -> {extension, sub_oids, sub_types, var!(mod)} + extension -> {extension, var!(mod)} end flat = decode_list(data, type) diff --git a/lib/postgrex/extensions/multirange.ex b/lib/postgrex/extensions/multirange.ex index 52cdfd7b..11bb2c20 100644 --- a/lib/postgrex/extensions/multirange.ex +++ b/lib/postgrex/extensions/multirange.ex @@ -27,7 +27,7 @@ defmodule Postgrex.Extensions.Multirange do def decode(_) do quote location: :keep do - <>, [_oid], [type], _ -> + <>, [_oid], [type] -> <<_num_ranges::int32(), ranges::binary>> = data # decode_list/2 defined by TypeModule diff --git a/lib/postgrex/extensions/range.ex b/lib/postgrex/extensions/range.ex index 69b1b5ac..92c0278f 100644 --- a/lib/postgrex/extensions/range.ex +++ b/lib/postgrex/extensions/range.ex @@ -35,7 +35,7 @@ defmodule Postgrex.Extensions.Range do def decode(_) do quote location: :keep do - <>, [_oid], [type], _ -> + <>, [_oid], [type] -> <> = binary # decode_list/2 defined by TypeModule diff --git a/lib/postgrex/extensions/record.ex b/lib/postgrex/extensions/record.ex index 26a8d614..f436c671 100644 --- a/lib/postgrex/extensions/record.ex +++ b/lib/postgrex/extensions/record.ex @@ -31,12 +31,12 @@ defmodule Postgrex.Extensions.Record do def decode(_) do quote location: :keep do - <>, nil, types, _ -> + <>, nil, types -> <> = binary # decode_tuple/3 defined by TypeModule decode_tuple(data, count, types) - <>, oids, types, _ -> + <>, oids, types -> <<_::int32(), data::binary>> = binary # decode_tuple/3 defined by TypeModule decode_tuple(data, oids, types) diff --git a/lib/postgrex/extensions/timestamp.ex b/lib/postgrex/extensions/timestamp.ex index 0bc6779c..27184109 100644 --- a/lib/postgrex/extensions/timestamp.ex +++ b/lib/postgrex/extensions/timestamp.ex @@ -28,8 +28,8 @@ defmodule Postgrex.Extensions.Timestamp do def decode(infinity?) do quote location: :keep do - <<8::int32(), microsecs::int64()>>, precision -> - unquote(__MODULE__).microsecond_to_elixir(microsecs, precision, unquote(infinity?)) + <<8::int32(), microsecs::int64()>> -> + unquote(__MODULE__).microsecond_to_elixir(microsecs, var!(mod), unquote(infinity?)) end end diff --git a/lib/postgrex/type_module.ex b/lib/postgrex/type_module.ex index 2c53ead6..41504e70 100644 --- a/lib/postgrex/type_module.ex +++ b/lib/postgrex/type_module.ex @@ -198,7 +198,7 @@ defmodule Postgrex.TypeModule do end defp encode_extension(extension, clause) do - case split_extension_encode(clause) do + case split_extension(clause) do {pattern, guard, body} -> encode_extension(extension, pattern, guard, body) @@ -224,7 +224,7 @@ defmodule Postgrex.TypeModule do end defp encode_super(extension, clause) do - case split_super_encode(clause) do + case split_super(clause) do {pattern, sub_oids, sub_types, guard, body} -> encode_super(extension, pattern, sub_oids, sub_types, guard, body) @@ -615,12 +615,11 @@ defmodule Postgrex.TypeModule do end defp decode_extension(extension, clause, dispatch, rest, acc, rem, full, rows) do - case split_extension_decode(clause) do - {pattern, mod, guard, body} -> + case split_extension(clause) do + {pattern, guard, body} -> decode_extension( extension, pattern, - mod, guard, body, dispatch, @@ -631,15 +630,14 @@ defmodule Postgrex.TypeModule do rows ) - {pattern, mod, body} -> - decode_extension(extension, pattern, mod, body, dispatch, rest, acc, rem, full, rows) + {pattern, body} -> + decode_extension(extension, pattern, body, dispatch, rest, acc, rem, full, rows) end end defp decode_extension( extension, pattern, - mod, guard, body, dispatch, @@ -652,7 +650,7 @@ defmodule Postgrex.TypeModule do quote do defp unquote(extension)( <>, - unquote(mod), + var!(mod), types, acc, unquote(rem), @@ -667,24 +665,24 @@ defmodule Postgrex.TypeModule do end end - defp unquote(extension)(<>, mod = unquote(mod), acc) + defp unquote(extension)(<>, var!(mod) = mod, acc) when unquote(guard) do unquote(extension)(rest, mod, [unquote(body) | acc]) end defp unquote(extension)( <>, - nil = unquote(mod), + var!(mod) = mod, acc, callback ) when unquote(guard) do - unquote(extension)(rest, nil, [unquote(body) | acc], callback) + unquote(extension)(rest, mod, [unquote(body) | acc], callback) end defp unquote(extension)( <>, - nil = unquote(mod), + var!(mod), oids, types, n, @@ -696,11 +694,11 @@ defmodule Postgrex.TypeModule do end end - defp decode_extension(extension, pattern, mod, body, dispatch, rest, acc, rem, full, rows) do + defp decode_extension(extension, pattern, body, dispatch, rest, acc, rem, full, rows) do quote do defp unquote(extension)( <>, - unquote(mod), + var!(mod), types, acc, unquote(rem), @@ -714,24 +712,24 @@ defmodule Postgrex.TypeModule do end end - defp unquote(extension)(<>, mod = unquote(mod), acc) do + defp unquote(extension)(<>, var!(mod), acc) do decoded = unquote(body) - unquote(extension)(rest, mod, [decoded | acc]) + unquote(extension)(rest, var!(mod), [decoded | acc]) end defp unquote(extension)( <>, - nil = unquote(mod), + var!(mod), acc, callback ) do decoded = unquote(body) - unquote(extension)(rest, nil, [decoded | acc], callback) + unquote(extension)(rest, var!(mod), [decoded | acc], callback) end defp unquote(extension)( <>, - nil = unquote(mod), + var!(mod), oids, types, n, @@ -760,29 +758,29 @@ defmodule Postgrex.TypeModule do end end - defp unquote(extension)(<<-1::int32(), rest::binary>>, mod, acc) do - unquote(extension)(rest, mod, [@null | acc]) + defp unquote(extension)(<<-1::int32(), rest::binary>>, var!(mod), acc) do + unquote(extension)(rest, var!(mod), [@null | acc]) end defp unquote(extension)(<<>>, _, acc) do acc end - defp unquote(extension)(<<-1::int32(), rest::binary>>, nil, acc, callback) do - unquote(extension)(rest, nil, [@null | acc], callback) + defp unquote(extension)(<<-1::int32(), rest::binary>>, var!(mod), acc, callback) do + unquote(extension)(rest, var!(mod), [@null | acc], callback) end defp unquote(extension)(<>, _, acc, callback) do callback.(rest, acc) end - defp unquote(extension)(<<-1::int32(), rest::binary>>, nil, oids, types, n, acc) do + defp unquote(extension)(<<-1::int32(), rest::binary>>, _mod, oids, types, n, acc) do decode_tuple(rest, oids, types, n, acc) end end end - defp split_extension_encode({:->, _, [head, body]}) do + defp split_extension({:->, _, [head, body]}) do case head do [{:when, _, [pattern, guard]}] -> {pattern, guard, body} @@ -792,31 +790,14 @@ defmodule Postgrex.TypeModule do end end - defp split_extension_decode({:->, _, [head, body]}) do - case head do - [{:when, _, [pattern, guard]}] -> - {pattern, quote(do: _), guard, body} - - [pattern] -> - {pattern, quote(do: _), body} - - [{:when, _, [pattern, modifier, guard]}] -> - {pattern, modifier, guard, body} - - [pattern, modifier] -> - {pattern, modifier, body} - end - end - defp decode_super(extension, clause, dispatch, rest, acc, rem, full, rows) do - case split_super_decode(clause) do - {pattern, oids, types, mod, guard, body} -> + case split_super(clause) do + {pattern, oids, types, guard, body} -> decode_super( extension, pattern, oids, types, - mod, guard, body, dispatch, @@ -827,13 +808,12 @@ defmodule Postgrex.TypeModule do rows ) - {pattern, oids, types, mod, body} -> + {pattern, oids, types, body} -> decode_super( extension, pattern, oids, types, - mod, body, dispatch, rest, @@ -850,7 +830,6 @@ defmodule Postgrex.TypeModule do pattern, sub_oids, sub_types, - mod, guard, body, dispatch, @@ -865,7 +844,7 @@ defmodule Postgrex.TypeModule do <>, unquote(sub_oids), unquote(sub_types), - unquote(mod), + var!(mod), types, acc, unquote(rem), @@ -884,19 +863,19 @@ defmodule Postgrex.TypeModule do <>, unquote(sub_oids), unquote(sub_types), - mod = unquote(mod), + var!(mod), acc ) when unquote(guard) do acc = [unquote(body) | acc] - unquote(extension)(rest, unquote(sub_oids), unquote(sub_types), mod, acc) + unquote(extension)(rest, unquote(sub_oids), unquote(sub_types), var!(mod), acc) end defp unquote(extension)( <>, unquote(sub_oids), unquote(sub_types), - nil = unquote(mod), + var!(mod), oids, types, n, @@ -913,7 +892,6 @@ defmodule Postgrex.TypeModule do pattern, sub_oids, sub_types, - mod, body, dispatch, rest, @@ -927,7 +905,7 @@ defmodule Postgrex.TypeModule do <>, unquote(sub_oids), unquote(sub_types), - unquote(mod), + var!(mod), types, acc, unquote(rem), @@ -945,18 +923,18 @@ defmodule Postgrex.TypeModule do <>, unquote(sub_oids), unquote(sub_types), - mod = unquote(mod), + var!(mod), acc ) do acc = [unquote(body) | acc] - unquote(extension)(rest, unquote(sub_oids), unquote(sub_types), mod, acc) + unquote(extension)(rest, unquote(sub_oids), unquote(sub_types), var!(mod), acc) end defp unquote(extension)( <>, unquote(sub_oids), unquote(sub_types), - nil = unquote(mod), + var!(mod), oids, types, n, @@ -988,8 +966,8 @@ defmodule Postgrex.TypeModule do end end - defp unquote(extension)(<<-1::int32(), rest::binary>>, sub_oids, sub_types, mod, acc) do - unquote(extension)(rest, sub_oids, sub_types, mod, [@null | acc]) + defp unquote(extension)(<<-1::int32(), rest::binary>>, sub_oids, sub_types, var!(mod), acc) do + unquote(extension)(rest, sub_oids, sub_types, var!(mod), [@null | acc]) end defp unquote(extension)(<<>>, _sub_oid, _sub_types, _mod, acc) do @@ -1000,7 +978,7 @@ defmodule Postgrex.TypeModule do <<-1::int32(), rest::binary>>, _sub_oids, _sub_types, - nil, + _mod, oids, types, n, @@ -1011,7 +989,7 @@ defmodule Postgrex.TypeModule do end end - defp split_super_encode({:->, _, [head, body]}) do + defp split_super({:->, _, [head, body]}) do case head do [{:when, _, [pattern, sub_oids, sub_types, guard]}] -> {pattern, sub_oids, sub_types, guard, body} @@ -1021,16 +999,6 @@ defmodule Postgrex.TypeModule do end end - defp split_super_decode({:->, _, [head, body]}) do - case head do - [{:when, _, [pattern, sub_oids, sub_types, modifier, guard]}] -> - {pattern, sub_oids, sub_types, modifier, guard, body} - - [pattern, sub_oids, sub_types, modifier] -> - {pattern, sub_oids, sub_types, modifier, body} - end - end - defp configure(extensions, opts) do defaults = Postgrex.Utils.default_extensions(opts) Enum.map(extensions ++ defaults, &configure/1)