summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MDK/Common/System.pm8
-rw-r--r--perl-MDK-Common.spec6
-rw-r--r--perl_checker.src/parser.mly10
-rw-r--r--perl_checker.src/parser_helper.ml14
-rw-r--r--perl_checker.src/parser_helper.mli10
5 files changed, 36 insertions, 12 deletions
diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm
index c41485b..7ef5fc7 100644
--- a/MDK/Common/System.pm
+++ b/MDK/Common/System.pm
@@ -300,7 +300,7 @@ sub setVarsInShMode {
@fields = keys %$l unless @fields;
MDK::Common::File::output($file,
- map { $l->{$_} ? "$_=$l->{$_}\n" : () } @fields
+ map { $l->{$_} ? "$_=$l->{$_}\n" : @{[]} } @fields
);
chmod $mod, $file;
}
@@ -310,8 +310,8 @@ sub setExportedVarsInSh {
@fields = keys %$l unless @fields;
MDK::Common::File::output($file,
- (map { $l->{$_} ? "$_=$l->{$_}\n" : () } @fields),
- @fields ? "export " . join(" ", @fields) . "\n" : (),
+ (map { $l->{$_} ? "$_=$l->{$_}\n" : @{[]} } @fields),
+ @fields ? "export " . join(" ", @fields) . "\n" : @{[]},
);
}
@@ -319,7 +319,7 @@ sub setExportedVarsInCsh {
my ($file, $l, @fields) = @_;
@fields = keys %$l unless @fields;
- MDK::Common::File::output($file, map { $l->{$_} ? "setenv $_ $l->{$_}\n" : () } @fields);
+ MDK::Common::File::output($file, map { $l->{$_} ? "setenv $_ $l->{$_}\n" : @{[]} } @fields);
}
sub template2file {
diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec
index ee3e00a..da4c27b 100644
--- a/perl-MDK-Common.spec
+++ b/perl-MDK-Common.spec
@@ -2,7 +2,7 @@
# do not change the version here, change in MDK/Common.pm.pl
%define version THEVERSION
-%define release 3mdk
+%define release 4mdk
Summary: Various simple functions
Name: perl-MDK-Common
@@ -50,6 +50,10 @@ rm -rf $RPM_BUILD_ROOT
# MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common
%changelog
+* Wed Dec 4 2002 Pixel <pixel@mandrakesoft.com> 1.0.4-4mdk
+- warn use of "cond ? list : ()" (use if_(cond, list) instead)
+- adapt MDK::Common::* to this (using @{[]} instead of () to avoid the warning)
+
* Mon Dec 2 2002 Pixel <pixel@mandrakesoft.com> 1.0.4-3mdk
- add output_with_perm(), cat_or_die()
- some more checks in perl_checker ($1 =~ /re/ is a warning)
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly
index 695e88a..45c0db8 100644
--- a/perl_checker.src/parser.mly
+++ b/perl_checker.src/parser.mly
@@ -233,10 +233,10 @@ term:
| term PATTERN_MATCH_NOT STRING {die_with_rawpos (sndsnd $3) "use a regexp, not a string"}
-| term QUESTION_MARK term COLON term {sp_p($2); sp_p($3); sp_p($4); sp_p($5); to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; prio_lo_after P_ternary $3; prio_lo_after P_ternary $5]) (sp_pos_range $1 $5)}
-| term QUESTION_MARK term COLON BRACKET expr BRACKET_END {sp_p($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); sp_p($7); to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; prio_lo_after P_ternary $3; sndfst $6]) (sp_pos_range $1 $7)}
-| term QUESTION_MARK BRACKET expr BRACKET_END COLON term {sp_p($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); sp_p($7); to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; sndfst $4; prio_lo_after P_ternary $7]) (sp_pos_range $1 $7)}
-| term QUESTION_MARK BRACKET expr BRACKET_END COLON BRACKET expr BRACKET_END {sp_p($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); sp_p($7); sp_p($8); sp_p($9); to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; sndfst $4; sndfst $8]) (sp_pos_range $1 $9)}
+| term QUESTION_MARK term COLON term {sp_p($2); sp_p($3); sp_p($4); sp_p($5); check_ternary_paras $3 $5; to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; prio_lo_after P_ternary $3; prio_lo_after P_ternary $5]) (sp_pos_range $1 $5)}
+| term QUESTION_MARK term COLON BRACKET expr BRACKET_END {sp_p($2); sp_p($3); check_ternary_para $3; sp_p($4); sp_p($5); sp_p($6); sp_p($7); check_ternary_para $1; to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; prio_lo_after P_ternary $3; Ref(I_hash, sndfst $6)]) (sp_pos_range $1 $7)}
+| term QUESTION_MARK BRACKET expr BRACKET_END COLON term {sp_p($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); sp_p($7); check_ternary_para $7; to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; Ref(I_hash, sndfst $4); prio_lo_after P_ternary $7]) (sp_pos_range $1 $7)}
+| term QUESTION_MARK BRACKET expr BRACKET_END COLON BRACKET expr BRACKET_END {sp_p($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); sp_p($7); sp_p($8); sp_p($9); to_Call_op_(P_ternary, "?:", [ prio_lo P_ternary $1 ; Ref(I_hash, sndfst $4); Ref(I_hash, sndfst $8)]) (sp_pos_range $1 $9)}
/* Unary operators and terms */
@@ -296,6 +296,8 @@ term:
| term ARROW word_or_scalar {sp_0($2); sp_0($3); (P_tok, to_Method_call(sndfst $1, fst $3, [])), sp_pos_range $1 $3} /* $foo->bar */
| term ARROW MULT parenthesized {check_MULT_is_x $3; sp_0($2); sp_0($3); sp_0($4); (P_tok, to_Method_call(sndfst $1, Ident(None, "x", get_pos $3), sndfst $4)), sp_pos_range $1 $4} /* $foo->bar(list) */
| term ARROW MULT {check_MULT_is_x $3; sp_0($2); sp_0($3); (P_tok, to_Method_call(sndfst $1, Ident(None, "x", get_pos $3), [])), sp_pos_range $1 $3} /* $foo->bar */
+| term ARROW FOR parenthesized {sp_0($2); sp_0($3); sp_0($4); (P_tok, to_Method_call(sndfst $1, Ident(None, fst $3, get_pos $3), sndfst $4)), sp_pos_range $1 $4} /* $foo->bar(list) */
+| term ARROW FOR {sp_0($2); sp_0($3); (P_tok, to_Method_call(sndfst $1, Ident(None, fst $3, get_pos $3), [])), sp_pos_range $1 $3} /* $foo->bar */
| NEW word { sp_n($2); (P_call_no_paren, to_Method_call(fst $2, Ident(None, "new", get_pos $1), [])), sp_pos_range $1 $2} /* new Class */
| NEW word_paren parenthesized { sp_n($2); sp_0($3); (P_call_no_paren, to_Method_call(fst $2, Ident(None, "new", get_pos $1), sndfst $3)), sp_pos_range $1 $3} /* new Class(...) */
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 1e03f0e..00b121d 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -15,7 +15,10 @@ let is_var_dollar_ = function
| Deref(I_scalar, Ident(None, "_", _)) -> true
| _ -> false
let is_var_number_match = function
- | Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && char_is_number s.[0]
+ | Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && s.[0] <> '0' && char_is_number s.[0]
+ | _ -> false
+let is_call = function
+ | Call _ -> true
| _ -> false
let is_parenthesized = function
@@ -279,6 +282,15 @@ let check_arrow_needed ((_, e), _) ter =
| Deref_with _ -> warn (sndsnd ter) "the arrow \"->\" is unneeded"
| _ -> ()
+let check_ternary_para ((_, e), _) =
+ match e with
+ | List [] -> warn_rule "you may use if_() here\n beware that the short-circuit semantic of ?: is not kept\n if you want to keep the short-circuit behaviour, replace () with @{[]} and there will be no warning anymore"
+ | _ -> ()
+
+let check_ternary_paras ((_, e1), _ as ter1) ((_, e2), _ as ter2) =
+ if not (is_call e1) then check_ternary_para ter2;
+ if not (is_call e2) then check_ternary_para ter1
+
let check_unneeded_var_dollar_ ((_, e), (_, pos)) =
if is_var_dollar_ e then warn pos "\"$_ =~ /regexp/\" can be written \"/regexp/\"" else
if is_var_number_match e then warn pos "do not use the result of a match (eg: $1) to match another pattern"
diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli
index e617547..d3f5396 100644
--- a/perl_checker.src/parser_helper.mli
+++ b/perl_checker.src/parser_helper.mli
@@ -8,6 +8,8 @@ val get_pos : 'a * ('b * ('c * 'd)) -> string * 'c * 'd
val var_dollar_ : Types.fromparser
val var_STDOUT : Types.fromparser
val is_var_dollar_ : Types.fromparser -> bool
+val is_var_number_match : Types.fromparser -> bool
+val is_call : Types.fromparser -> bool
val is_parenthesized : Types.fromparser -> bool
val un_parenthesize : Types.fromparser -> Types.fromparser
val un_parenthesize_full : Types.fromparser -> Types.fromparser
@@ -60,12 +62,16 @@ val check_hash_subscript :
('a * Types.fromparser) * ('b * (int * int)) -> unit
val check_arrow_needed :
('a * Types.fromparser) * 'b -> 'c * ('d * (int * int)) -> unit
+val check_ternary_para : ('a * Types.fromparser) * ('b * (int * int)) -> unit
+val check_ternary_paras :
+ ('a * Types.fromparser) * ('b * (int * int)) ->
+ ('c * Types.fromparser) * ('d * (int * int)) -> unit
val check_unneeded_var_dollar_ :
('a * Types.fromparser) * ('b * (int * int)) -> unit
-val check_unneeded_var_dollar_s :
- ('a * Types.fromparser) * ('b * (int * int)) -> unit
val check_unneeded_var_dollar_not :
('a * Types.fromparser) * ('b * (int * int)) -> unit
+val check_unneeded_var_dollar_s :
+ ('a * Types.fromparser) * ('b * (int * int)) -> unit
val check_MULT_is_x : string * 'a -> unit
val check_my : string * 'a -> unit
val check_foreach : string * ('a * (int * int)) -> unit