summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-04-01 14:32:49 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-04-01 14:32:49 +0000
commitde6d11dc8308b6997ba86c1494613e3242a9a6a6 (patch)
tree5cc08ad1f7abccf348da17fb784bc30e2775f6f7 /perl_checker.src/parser_helper.ml
parent0b8a321a640a6a20578d5dbdd70aab53b5ee70c8 (diff)
downloadperl-MDK-Common-de6d11dc8308b6997ba86c1494613e3242a9a6a6.tar
perl-MDK-Common-de6d11dc8308b6997ba86c1494613e3242a9a6a6.tar.gz
perl-MDK-Common-de6d11dc8308b6997ba86c1494613e3242a9a6a6.tar.bz2
perl-MDK-Common-de6d11dc8308b6997ba86c1494613e3242a9a6a6.tar.xz
perl-MDK-Common-de6d11dc8308b6997ba86c1494613e3242a9a6a6.zip
- warn <always true> || ... (eg: 1 || foo())
- warn <always false> || ... - warn <always true> && ... - warn <always false> && ... - suggest @$foo instead of @{$foo} - suggest $foo->[0] instead of ${$foo}[0]
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml28
1 files changed, 27 insertions, 1 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 832ad76..f16ca14 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -58,6 +58,19 @@ let rec un_parenthesize_full = function
| List[e] -> un_parenthesize_full e
| e -> e
+let is_always_true = function
+ | Num(n, _) -> float_of_string n <> 0.
+ | Raw_string(s, _) -> s <> ""
+ | String(l, _) -> l <> []
+ | Ref _ -> true
+ | _ -> false
+
+let is_always_false = function
+ | Num(n, _) -> float_of_string n = 0.
+ | Raw_string(s, _) -> s = ""
+ | String(l, _) -> l = []
+ | _ -> false
+
let not_complex e =
if is_parenthesized e then true else
let rec not_complex_ op = function
@@ -296,7 +309,7 @@ let check_parenthesized_first_argexpr_with_Ident ident ((prio, e), _ as ex) =
(match e with
| [e] when is_parenthesized e -> ()
| _ -> warn_rule "use parentheses around argument (otherwise it might cause syntax errors if the package is \"require\"d and not \"use\"d")
- | Ident(None, word, _) when List.mem word ["ref"] ->
+ | Ident(None, word, _) when List.mem word ["ref" ; "readlink"] ->
if prio <> P_tok then warn_rule "use parentheses around argument"
| _ -> ());
check_parenthesized_first_argexpr (string_of_Ident ident) ex
@@ -318,6 +331,11 @@ let check_arrow_needed ((_, e), _) ter =
| Deref_with _ -> warn (sndsnd ter) "the arrow \"->\" is unneeded"
| _ -> ()
+let check_scalar_subscripted (e, _) =
+ match e with
+ | Deref(I_scalar, Deref _) -> warn_rule "for complex dereferencing, use \"->\""
+ | _ -> ()
+
let check_ternary_paras(cond, a, b) =
let rec dont_need_short_circuit_rec = function
| Num _
@@ -432,6 +450,9 @@ let deref_raw context e =
| Raw_string(s, pos) ->
let fq, ident = split_name_or_fq_name s in
Ident(fq, ident, pos)
+ | Deref(I_scalar, (Ident _ as ident)) ->
+ warn_rule (sprintf "%s{$%s} can be written %s$%s" (context2s context) (string_of_Ident ident) (context2s context) (string_of_Ident ident));
+ e
| _ -> e
in Deref(context, e)
@@ -508,6 +529,11 @@ let cook_call_op(op, para, pos) =
| "=", [ Deref(I_star, (Ident _ as f1)); (Anonymous_sub _ as sub) ] ->
sub_declaration (f1, "") [ sub ]
+ | "||", e :: _ when is_always_true e -> warn_rule "<constant> || ... is the same as <constant>"; call
+ | "&&", e :: _ when is_always_false e -> warn_rule "<constant> && ... is the same as <constant>"; call
+ | "||", e :: _ when is_always_false e -> warn_rule "<constant> || ... is the same as ..."; call
+ | "&&", e :: _ when is_always_true e -> warn_rule "<constant> && ... is the same as ..."; call
+
| _ ->
call