diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-02-14 10:39:00 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-02-14 10:39:00 +0000 |
commit | cd1285dd789ba84b526ade6c4f1e5d77c49a32a9 (patch) | |
tree | dd96bf139f0015d308e167c26bdf8dc09d6c28c2 /perl_checker.src | |
parent | c546ae4661be1e051df636a8b326ffabc8611201 (diff) | |
download | perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.gz perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.bz2 perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.xz perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.zip |
don't suggest to replace "@foo ? @foo : @bar" with "@foo || @bar", this is wrong!
Diffstat (limited to 'perl_checker.src')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 26 |
1 files changed, 18 insertions, 8 deletions
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) |