summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-05-23 13:45:12 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-05-23 13:45:12 +0000
commit23d1206401f04a5445f66a56bb7fd487ae8083e0 (patch)
tree0f806f9ce5d3dc501b4289269c0b4787c068ec44 /perl_checker.src
parentc9bfa38fe2413feb0c4495242fa8886c7f4669d3 (diff)
downloadperl_checker-23d1206401f04a5445f66a56bb7fd487ae8083e0.tar
perl_checker-23d1206401f04a5445f66a56bb7fd487ae8083e0.tar.gz
perl_checker-23d1206401f04a5445f66a56bb7fd487ae8083e0.tar.bz2
perl_checker-23d1206401f04a5445f66a56bb7fd487ae8083e0.tar.xz
perl_checker-23d1206401f04a5445f66a56bb7fd487ae8083e0.zip
- suggest any instead of grep in scalar context
- suggest foreach instead of map in empty context
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser.mly2
-rw-r--r--perl_checker.src/parser_helper.ml6
-rw-r--r--perl_checker.src/parser_helper.mli15
3 files changed, 19 insertions, 4 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly
index 0395859..d2dc1fd 100644
--- a/perl_checker.src/parser.mly
+++ b/perl_checker.src/parser.mly
@@ -267,7 +267,7 @@ term:
| DECR term {sp_0($2); mcontext_check M_int $2; to_Call_op_ (M_mixed [M_int ; M_none]) P_tight "--" [$2.any.expr] $1 $2}
| term INCR {sp_0($2); mcontext_check M_int $1; to_Call_op_ (M_mixed [M_int ; M_none]) P_tight "++ post" [$1.any.expr] $1 $2}
| term DECR {sp_0($2); mcontext_check M_int $1; to_Call_op_ (M_mixed [M_int ; M_none]) P_tight "-- post" [$1.any.expr] $1 $2}
-| NOT argexpr {warn_rule "don't use \"not\", use \"!\" instead"; to_Call_op_ (mcontext_unop M_scalar $2) P_and "not" ($2.any.expr) $1 $2}
+| NOT argexpr {warn_rule "don't use \"not\", use \"!\" instead"; to_Call_op_ (mcontext_unop_l M_scalar $2) P_and "not" ($2.any.expr) $1 $2}
/* Constructors for anonymous data */
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 0e37cf5..e19dfe1 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -978,6 +978,9 @@ let mcontext_check_raw wanted_mcontext esp f_lower f_greater f_err =
f_err())
let mcontext_check wanted_mcontext esp =
+ (match un_parenthesize_full esp.any.expr with
+ | Call(Deref(I_func, Ident(None, "grep", _)), _) -> warn_rule "in scalar context, use \"any\" instead of \"grep\""
+ | _ -> ());
mcontext_check_raw wanted_mcontext esp (fun () -> ()) (fun () -> ()) (fun () -> ())
let mcontext_symops wanted_mcontext esp1 esp2 =
@@ -1003,6 +1006,8 @@ let mcontext_rightops wanted_mcontext esp1 esp2 =
let mcontext_unop wanted_mcontext esp = mcontext_check wanted_mcontext esp ; wanted_mcontext
+let mcontext_unop_l wanted_mcontext esp = mcontext_unop wanted_mcontext { esp with any = { esp.any with expr = List esp.any.expr } }
+
let mcontext_check_non_none esp =
if esp.mcontext = M_none then warn_rule "() context not accepted here"
@@ -1014,6 +1019,7 @@ let mcontext_check_none esp =
match esp.any with
| [List [Num("1", _)]; Semi_colon] -> () (* allow "1;" for package return value. It would be much better to check we are at toplevel, but hell i don't want to wire this information up to here *)
| [List [Call_op ("<>", [Ident (None, "STDIN", _)], _)]; Semi_colon] -> () (* allow <STDIN> to ask "press return" *)
+ | [List [Call(Deref(I_func, Ident(None, "map", _)), _)]; Semi_colon] -> warn_rule "if you don't use the return value, use \"foreach\" instead of \"map\""
| _ -> warn_rule "value is dropped"
let mcontext_op_assign left right =
diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli
index 69f559d..f43c6b1 100644
--- a/perl_checker.src/parser_helper.mli
+++ b/perl_checker.src/parser_helper.mli
@@ -246,15 +246,24 @@ val mcontext_check_raw :
Types.maybe_context ->
'a Types.any_spaces_pos ->
(unit -> 'b) -> (unit -> 'b) -> (unit -> 'b) -> 'b
-val mcontext_check : Types.maybe_context -> 'a Types.any_spaces_pos -> unit
+val mcontext_check :
+ Types.maybe_context ->
+ Types.fromparser Types.prio_anyexpr Types.any_spaces_pos -> unit
val mcontext_symops :
Types.maybe_context ->
'a Types.any_spaces_pos -> 'b Types.any_spaces_pos -> Types.maybe_context
val mcontext_rightops :
Types.maybe_context ->
- 'a Types.any_spaces_pos -> 'b Types.any_spaces_pos -> Types.maybe_context
+ Types.fromparser Types.prio_anyexpr Types.any_spaces_pos ->
+ 'a Types.any_spaces_pos -> Types.maybe_context
val mcontext_unop :
- Types.maybe_context -> 'a Types.any_spaces_pos -> Types.maybe_context
+ Types.maybe_context ->
+ Types.fromparser Types.prio_anyexpr Types.any_spaces_pos ->
+ Types.maybe_context
+val mcontext_unop_l :
+ Types.maybe_context ->
+ Types.fromparser list Types.prio_anyexpr Types.any_spaces_pos ->
+ Types.maybe_context
val mcontext_check_non_none : 'a Types.any_spaces_pos -> unit
val mcontext_check_none : Types.fromparser list Types.any_spaces_pos -> unit
val mcontext_op_assign :