File 4685-epp-Eliminate-old-style-catches.patch of Package erlang
From f2d9408fe7fc647db315ef8498987fe34a332dc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Sat, 11 Jan 2025 09:44:55 +0100
Subject: [PATCH 5/7] epp: Eliminate old-style catches
---
lib/stdlib/src/epp.erl | 67 +++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 34 deletions(-)
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index fb813632a0..8a67475aa1 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -1156,15 +1154,16 @@ scan_toks([{'-',_Lh},{atom,_Le,elif}=Elif|Toks], From, St) ->
scan_toks([{'-',_Lh},{atom,_Le,endif}=Endif|Toks], From, St) ->
scan_endif(Toks, Endif, From, St);
scan_toks([{'-',_Lh},{atom,_Lf,file}=FileToken|Toks0], From, St) ->
- case catch expand_macros(Toks0, St) of
+ try expand_macros(Toks0, St) of
Toks1 when is_list(Toks1) ->
- scan_file(Toks1, FileToken, From, St);
- {error,ErrL,What} ->
- epp_reply(From, {error,{ErrL,epp,What}}),
- wait_req_scan(St)
+ scan_file(Toks1, FileToken, From, St)
+ catch
+ throw:{error,ErrL,What} ->
+ epp_reply(From, {error,{ErrL,epp,What}}),
+ wait_req_scan(St)
end;
scan_toks(Toks0, From, St) ->
- case catch expand_macros(Toks0, St#epp{fname=Toks0}) of
+ try expand_macros(Toks0, St#epp{fname=Toks0}) of
Toks1 when is_list(Toks1) ->
InPrefix =
St#epp.in_prefix
@@ -1177,8 +1176,9 @@ scan_toks(Toks0, From, St) ->
end,
epp_reply(From, {ok,Toks1}),
wait_req_scan(St#epp{in_prefix = InPrefix,
- macs=scan_module(Toks1, St#epp.macs)});
- {error,ErrL,What} ->
+ macs=scan_module(Toks1, St#epp.macs)})
+ catch
+ throw:{error,ErrL,What} ->
epp_reply(From, {error,{ErrL,epp,What}}),
wait_req_scan(St)
end.
@@ -1361,19 +1361,21 @@ scan_define(Toks, Def, From, St) ->
wait_req_scan(St).
scan_define_1([{',',_}=Comma|Toks], Mac,_Def, From, St) ->
- case catch macro_expansion(Toks, Comma) of
+ try macro_expansion(Toks, Comma) of
Expansion when is_list(Expansion) ->
- scan_define_2(none, {none,Expansion}, Mac, From, St);
- {error,ErrL,What} ->
+ scan_define_2(none, {none,Expansion}, Mac, From, St)
+ catch
+ throw:{error,ErrL,What} ->
epp_reply(From, {error,{ErrL,epp,What}}),
wait_req_scan(St)
end;
scan_define_1([{'(',_Ac}=T|Toks], Mac, _Def, From, St) ->
- case catch macro_pars(Toks, [], T) of
+ try macro_pars(Toks, [], T) of
{ok,{As,_}=MacroDef} ->
Len = length(As),
- scan_define_2(Len, MacroDef, Mac, From, St);
- {error,ErrL,What} ->
+ scan_define_2(Len, MacroDef, Mac, From, St)
+ catch
+ throw:{error,ErrL,What} ->
epp_reply(From, {error,{ErrL,epp,What}}),
wait_req_scan(St)
end;
@@ -2104,15 +2106,11 @@ expand_arg([], Ts, Anno, Rest, Bs) ->
update_fun_name(Token, #epp{fname=Toks0}=St) when is_list(Toks0) ->
%% ?FUNCTION_NAME or ?FUNCTION_ARITY is used for the first time in
%% a function. First expand macros (except ?FUNCTION_NAME and
- %% ?FUNCTION_ARITY) in the form.
-
- Toks1 = (catch expand_macros(Toks0, St#epp{fname=undefined})),
-
- %% Now extract the name and arity from the stream of tokens, and store
- %% the result in the #epp{} record so we don't have to do it
- %% again.
+ %% ?FUNCTION_ARITY) in the form, and then extract the name and
+ %% arity from the stream of tokens, and store the result in the
+ %% #epp{} record so we don't have to do it again.
- case Toks1 of
+ try expand_macros(Toks0, St#epp{fname=undefined}) of
[{atom,_,Name},{'(',_}|Toks] ->
%% This is the beginning of a function definition.
%% Scan the token stream up to the matching right
@@ -2124,12 +2122,13 @@ update_fun_name(Token, #epp{fname=Toks0}=St) when is_list(Toks0) ->
%% of a form. Does not make sense.
{var,_,Macro} = Token,
throw({error,loc(Token),{illegal_function_usage,Macro}});
- _ when is_list(Toks1) ->
+ Toks1 when is_list(Toks1) ->
%% Not the beginning of a function (an attribute or a
%% syntax error).
{var,_,Macro} = Token,
- throw({error,loc(Token),{illegal_function,Macro}});
- _ ->
+ throw({error,loc(Token),{illegal_function,Macro}})
+ catch
+ throw:_ ->
%% A macro expansion error. Return a dummy value and
%% let the caller notice and handle the error.
St#epp{fname={'_',0}}
@@ -2266,21 +2265,21 @@ wait_epp_reply(Epp, Mref) ->
end
end.
-expand_var([$$ | _] = NewName) ->
- case catch expand_var1(NewName) of
- {ok, ExpName} ->
- ExpName;
- _ ->
+expand_var("$" ++ _ = NewName) ->
+ try
+ expand_var1(NewName)
+ catch
+ error:_ ->
NewName
end;
expand_var(NewName) ->
NewName.
expand_var1(NewName) ->
- [[$$ | Var] | Rest] = filename:split(NewName),
+ ["$" ++ Var | Rest] = filename:split(NewName),
Value = os:getenv(Var),
true = Value =/= false,
- {ok, fname_join([Value | Rest])}.
+ fname_join([Value | Rest]).
fname_join(["." | [_|_]=Rest]) ->
fname_join(Rest);
--
2.51.0