summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-10-13 09:13:30 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-10-13 09:13:30 +0000
commit0e8d5a3cd1b213b624e8c3bab928b514220db27a (patch)
tree4d4dd292e2f739ee6e9ae57cbd866c9cae1ee9da /perl_checker.src/parser_helper.ml
parentb806dd8ca5c137d874e94294fd73543a4682fe1a (diff)
downloadperl-MDK-Common-0e8d5a3cd1b213b624e8c3bab928b514220db27a.tar
perl-MDK-Common-0e8d5a3cd1b213b624e8c3bab928b514220db27a.tar.gz
perl-MDK-Common-0e8d5a3cd1b213b624e8c3bab928b514220db27a.tar.bz2
perl-MDK-Common-0e8d5a3cd1b213b624e8c3bab928b514220db27a.tar.xz
perl-MDK-Common-0e8d5a3cd1b213b624e8c3bab928b514220db27a.zip
check 'xxx' if $xxx (=> value is dropped)
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml55
1 files changed, 29 insertions, 26 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 5a147eb..d797daf 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -1008,32 +1008,6 @@ let call_one_scalar_para { any = e ; pos = pos } para esp_start esp_end =
new_pesp M_unknown P_mul (call(Deref(I_func, Ident(None, e, raw_pos2pos pos)), para)) esp_start esp_end
-let call_op_if_infix left right esp_start esp_end =
- (match left, right with
- | List [Call_op("=", [Deref(context, _); _], _)], _ when non_scalar_context context -> ()
- | List [Call_op("=", [v; _], _)],
- List [Call_op("not", [v'], _)] when is_same_fromparser v v' ->
- warn_rule "\"$foo = ... if !$foo\" can be written \"$foo ||= ...\""
- | _ -> ());
- let pos = raw_pos_range esp_start esp_end in
- new_any M_none (Call_op("if infix", [ left ; right], raw_pos2pos pos)) esp_start.spaces pos
-
-let call_op_unless_infix left right esp_start esp_end =
- (match left, right with
- | List [Call_op("=", [Deref(context, _); _], _)], _ when non_scalar_context context -> ()
- | List [Call_op("=", [v; _], _)], List [v'] when is_same_fromparser v v' ->
- warn_rule "\"$foo = ... unless $foo\" can be written \"$foo ||= ...\""
- | _ -> ());
- (match right with
- | List [Call_op(op, _, _)] ->
- (match op with
- | "&&" | "||" | "not" | "ne" | "?:" -> warn_rule "don't use \"unless\" when the condition is complex, use \"if\" instead"
- | _ -> ());
- | _ -> ());
- let pos = raw_pos_range esp_start esp_end in
- new_any M_none (Call_op("unless infix", [ left ; right], raw_pos2pos pos)) esp_start.spaces pos
-
-
let (current_lexbuf : Lexing.lexbuf option ref) = ref None
let rec list2tokens l =
@@ -1283,6 +1257,35 @@ let mtuple_context_concat c1 c2 =
| M_tuple l, _ -> M_tuple (l @ [c2])
| _ -> M_tuple [c1 ; c2]
+let call_op_if_infix left right esp_start esp_end =
+ (match left, right with
+ | List [Call_op("=", [Deref(context, _); _], _)], _ when non_scalar_context context -> ()
+ | List [Call_op("=", [v; _], _)],
+ List [Call_op("not", [v'], _)] when is_same_fromparser v v' ->
+ warn_rule "\"$foo = ... if !$foo\" can be written \"$foo ||= ...\""
+ | _ -> ());
+
+ mcontext_check_none "value is dropped" [left] esp_start;
+ let pos = raw_pos_range esp_start esp_end in
+ new_any M_none (Call_op("if infix", [ left ; right], raw_pos2pos pos)) esp_start.spaces pos
+
+let call_op_unless_infix left right esp_start esp_end =
+ (match left, right with
+ | List [Call_op("=", [Deref(context, _); _], _)], _ when non_scalar_context context -> ()
+ | List [Call_op("=", [v; _], _)], List [v'] when is_same_fromparser v v' ->
+ warn_rule "\"$foo = ... unless $foo\" can be written \"$foo ||= ...\""
+ | _ -> ());
+ (match right with
+ | List [Call_op(op, _, _)] ->
+ (match op with
+ | "&&" | "||" | "not" | "ne" | "?:" -> warn_rule "don't use \"unless\" when the condition is complex, use \"if\" instead"
+ | _ -> ());
+ | _ -> ());
+
+ mcontext_check_none "value is dropped" [left] esp_start;
+ let pos = raw_pos_range esp_start esp_end in
+ new_any M_none (Call_op("unless infix", [ left ; right], raw_pos2pos pos)) esp_start.spaces pos
+
let symops pri para_context return_context op_str left op right =
sp_same op right;
let skip_context_check =