summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-02-05 13:39:37 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-02-05 13:39:37 +0000
commitaf260a0724fde72626e639bf59115b356917dd28 (patch)
tree9df2092d5e43fe55aa9b6a8ca8d4bd0cfa41fd38 /perl_checker.src/parser_helper.ml
parentdc5032ed00875c1cf4f978ddeb07e5967f9488f8 (diff)
downloadperl_checker-af260a0724fde72626e639bf59115b356917dd28.tar
perl_checker-af260a0724fde72626e639bf59115b356917dd28.tar.gz
perl_checker-af260a0724fde72626e639bf59115b356917dd28.tar.bz2
perl_checker-af260a0724fde72626e639bf59115b356917dd28.tar.xz
perl_checker-af260a0724fde72626e639bf59115b356917dd28.zip
warn when using $l[$#l], advice $l[-1] instead
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml10
1 files changed, 9 insertions, 1 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 9230074..680b571 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -372,6 +372,14 @@ let rec only_one (l, (spaces, pos)) =
| [] -> die_with_rawpos pos "you must give one argument"
| _ -> die_with_rawpos pos "you must give only one argument"
+let only_one_array_ref (l, (spaces, pos)) =
+ let e = only_one (l, (spaces, pos)) in
+ (match e with
+ | Call_op("last_array_index", [Deref(I_array, e)], _) ->
+ warn pos (sprintf "you can replace $#%s with -1" (string_of_Ident e))
+ | _ -> ());
+ e
+
let only_one_in_List ((_, e), both) =
match e with
| List l -> only_one(l, both)
@@ -396,7 +404,7 @@ let to_List = function
| [e] -> e
| l -> List l
-let deref_arraylen e = Call(Deref(I_func, Ident(None, "int", raw_pos2pos bpos)), [Deref(I_array, e)])
+let deref_arraylen e = Call_op("last_array_index", [Deref(I_array, e)], raw_pos2pos bpos)
let to_Ident ((fq, name), (_, pos)) = Ident(fq, name, raw_pos2pos pos)
let to_Raw_string (s, (_, pos)) = Raw_string(s, raw_pos2pos pos)
let to_Method_call (object_, method_, para) =