From 1aca3be2ddf68abe1346a70f586f30757abb6782 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 14 Feb 2003 10:39:00 +0000 Subject: don't suggest to replace "@foo ? @foo : @bar" with "@foo || @bar", this is wrong! --- perl_checker.src/parser_helper.ml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'perl_checker.src') diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 2682bfb..edd0023 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -27,6 +27,23 @@ let is_var_number_match = function | Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && s.[0] <> '0' && char_is_number s.[0] | _ -> false +let non_scalar_context context = context = I_hash || context = I_array +let is_scalar_context context = context = I_scalar + +let is_not_a_scalar = function + | Deref_with(_, context, _, _) + | Deref(context, _) -> non_scalar_context context + | _ -> false + +let is_a_scalar = function + | Ref _ + | Num _ + | Raw_string _ + | String _ -> true + | Deref_with(_, context, _, _) + | Deref(context, _) -> is_scalar_context context + | _ -> false + let is_parenthesized = function | List[] | List[List _] -> true @@ -66,8 +83,6 @@ let context2s = function | I_star -> "*" let variable2s(context, ident) = context2s context ^ ident -let non_scalar_context context = context = I_hash || context = I_array - let rec is_same_fromparser a b = match a, b with | Undef, Undef -> true @@ -329,7 +344,7 @@ let check_ternary_paras(cond, a, b) = in if dont_need_short_circuit a || is_same_fromparser cond a then check_ternary_para b; if dont_need_short_circuit b || is_same_fromparser cond b then check_ternary_para a; - if is_same_fromparser cond a && dont_need_short_circuit b then warn_rule "you can replace \"$foo ? $foo : $bar\" with \"$foo || $bar\""; + if is_same_fromparser cond a && dont_need_short_circuit b && is_a_scalar a && is_a_scalar b then warn_rule "you can replace \"$foo ? $foo : $bar\" with \"$foo || $bar\""; [ cond; a; b ] let check_unneeded_var_dollar_ ((_, e), (_, pos)) = @@ -401,11 +416,6 @@ let rec is_only_one_in_List = function | [List l] -> is_only_one_in_List l | [_] -> true | _ -> false - -let is_not_a_scalar = function - | Deref_with(_, context, _, _) - | Deref(context, _) -> non_scalar_context context - | _ -> false let maybe_to_Raw_string = function | Ident(None, s, pos) -> Raw_string(s, pos) -- cgit v1.2.1