From 7c8b2a0d705ede4bc0ec1bfe8e0afe5a9942809b Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 21 Jun 2017 09:41:52 +0200 Subject: xref: Improve handling of Unicode The updates of xref_base:analysis() are cosmetic (the strings are parsed by the Erlang scanner only). --- lib/tools/src/xref_base.erl | 22 +++++++++++----------- lib/tools/src/xref_parser.yrl | 6 +++--- lib/tools/src/xref_utils.erl | 13 +++++++++---- 3 files changed, 23 insertions(+), 18 deletions(-) (limited to 'lib/tools/src') diff --git a/lib/tools/src/xref_base.erl b/lib/tools/src/xref_base.erl index 8d2cc07e40..3199b28acb 100644 --- a/lib/tools/src/xref_base.erl +++ b/lib/tools/src/xref_base.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2016. All Rights Reserved. +%% Copyright Ericsson AB 2000-2017. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -405,21 +405,21 @@ analysis(exports_not_used, _) -> %% Local calls are not considered here. "X * UU" would do otherwise. "X - XU"; analysis({call, F}, functions) -> - make_query("range (E | ~w : Fun)", [F]); + make_query("range (E | ~tw : Fun)", [F]); analysis({use, F}, functions) -> - make_query("domain (E || ~w : Fun)", [F]); + make_query("domain (E || ~tw : Fun)", [F]); analysis({module_call, M}, _) -> - make_query("range (ME | ~w : Mod)", [M]); + make_query("range (ME | ~tw : Mod)", [M]); analysis({module_use, M}, _) -> - make_query("domain (ME || ~w : Mod)", [M]); + make_query("domain (ME || ~tw : Mod)", [M]); analysis({application_call, A}, _) -> - make_query("range (AE | ~w : App)", [A]); + make_query("range (AE | ~tw : App)", [A]); analysis({application_use, A}, _) -> - make_query("domain (AE || ~w : App)", [A]); + make_query("domain (AE || ~tw : App)", [A]); analysis({release_call, R}, _) -> - make_query("range (RE | ~w : Rel)", [R]); + make_query("range (RE | ~tw : Rel)", [R]); analysis({release_use, R}, _) -> - make_query("domain (RE || ~w : Rel)", [R]); + make_query("domain (RE || ~tw : Rel)", [R]); analysis(deprecated_function_calls, functions) -> "XC || DF"; analysis({deprecated_function_calls,Flag}, functions) -> @@ -1833,9 +1833,9 @@ message(true, What, Arg) -> unreadable -> io:format("Skipping ~ts (unreadable)~n", [Arg]); xref_attr -> - io:format("~ts: Skipping 'xref' attribute ~w~n", Arg); + io:format("~ts: Skipping 'xref' attribute ~tw~n", Arg); depr_attr -> - io:format("~ts: Skipping 'deprecated' attribute ~w~n", Arg); + io:format("~ts: Skipping 'deprecated' attribute ~tw~n", Arg); lib_search -> io:format("Scanning library path for BEAM files... ", []); lib_check -> diff --git a/lib/tools/src/xref_parser.yrl b/lib/tools/src/xref_parser.yrl index 0711da79e2..5ee6419ff5 100644 --- a/lib/tools/src/xref_parser.yrl +++ b/lib/tools/src/xref_parser.yrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2016. All Rights Reserved. +%% Copyright Ericsson AB 2000-2017. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -170,7 +170,7 @@ is_prefix_op('#') -> numeric; is_prefix_op(_) -> false. check_regexp(String) -> - case re:compile(String) of + case re:compile(String, [unicode]) of {ok, _Expr} -> {regexpr, String}; {error, {ErrString, Position}} -> @@ -274,7 +274,7 @@ mfa2s({M,F,A}) -> [c2s(M),':',c2s(F),'/',A]. c2s(C) -> - [S] = io_lib:format("~p", [C]), + [S] = io_lib:format("~tp", [C]), list_to_atom(S). re(variable) -> ['_']; diff --git a/lib/tools/src/xref_utils.erl b/lib/tools/src/xref_utils.erl index b0c168e018..02e207d40c 100644 --- a/lib/tools/src/xref_utils.erl +++ b/lib/tools/src/xref_utils.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2016. All Rights Reserved. +%% Copyright Ericsson AB 2000-2017. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -638,14 +638,14 @@ neighbours([], G, Fun, VT, L, _V, Vs) -> neighbours(Vs, G, Fun, VT, L). match_list(L, RExpr) -> - {ok, Expr} = re:compile(RExpr), + {ok, Expr} = re:compile(RExpr, [unicode]), filter(fun(E) -> match(E, Expr) end, L). match_one(VarL, Con, Col) -> select_each(VarL, fun(E) -> Con =:= element(Col, E) end). match_many(VarL, RExpr, Col) -> - {ok, Expr} = re:compile(RExpr), + {ok, Expr} = re:compile(RExpr, [unicode]), select_each(VarL, fun(E) -> match(element(Col, E), Expr) end). match(I, Expr) when is_integer(I) -> @@ -653,7 +653,12 @@ match(I, Expr) when is_integer(I) -> {match, [{0,length(S)}]} =:= re:run(S, Expr, [{capture, first}]); match(A, Expr) when is_atom(A) -> S = atom_to_list(A), - {match, [{0,length(S)}]} =:= re:run(S, Expr, [{capture, first}]). + case re:run(S, Expr, [{capture, first}]) of + {match, [{0,Size}]} -> + Size =:= byte_size(unicode:characters_to_binary(S)); + _ -> + false + end. select_each([{Mod,Funs} | L], Pred) -> case filter(Pred, Funs) of -- cgit v1.2.3