summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-02-14 10:39:00 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-02-14 10:39:00 +0000
commit1aca3be2ddf68abe1346a70f586f30757abb6782 (patch)
tree8d94869aed4aaf24041851d6bf4cb0297c6b57c0 /perl_checker.src/parser_helper.ml
parent5cd7d2b782f015cbf8adec6244d34c2cd5823893 (diff)
downloadperl_checker-1aca3be2ddf68abe1346a70f586f30757abb6782.tar
perl_checker-1aca3be2ddf68abe1346a70f586f30757abb6782.tar.gz
perl_checker-1aca3be2ddf68abe1346a70f586f30757abb6782.tar.bz2
perl_checker-1aca3be2ddf68abe1346a70f586f30757abb6782.tar.xz
perl_checker-1aca3be2ddf68abe1346a70f586f30757abb6782.zip
don't suggest to replace "@foo ? @foo : @bar" with "@foo || @bar", this is wrong!
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml26
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)