Browse code

core script parsing: better error & warning for while() & switch()

- while() checks in-line with the if() checks (warnings on
non-int, parse error on invalid expression).
- switch() - throw a parse error if the switch() expression or
body is invalid (type-wise)

Andrei Pelinescu-Onciul authored on 14/05/2009 16:10:37
Showing 1 changed files
... ...
@@ -1958,15 +1958,21 @@ case_stms:
1958 1958
 switch_cmd:
1959 1959
 	  SWITCH rval_expr LBRACE case_stms RBRACE { 
1960 1960
 		$$=0;
1961
-		if ($2==0) yyerror("bad expression in switch(...)");
1962
-		else if ($4==0) yyerror ("bad switch body");
1963
-		else if (case_check_default($4)!=0)
1961
+		if ($2==0){
1962
+			yyerror("bad expression in switch(...)");
1963
+			YYERROR;
1964
+		}else if ($4==0){
1965
+			yyerror ("bad switch body");
1966
+			YYERROR;
1967
+		}else if (case_check_default($4)!=0){
1964 1968
 			yyerror_at(&$2->fpos, "bad switch(): too many "
1965 1969
 							"\"default:\" labels\n");
1966
-		else if (case_check_type($4)!=0)
1970
+			YYERROR;
1971
+		}else if (case_check_type($4)!=0){
1967 1972
 			yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
1968 1973
 							" string/RE cases not allowed\n");
1969
-		else{
1974
+			YYERROR;
1975
+		}else{
1970 1976
 			$$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
1971 1977
 			if ($$==0) {
1972 1978
 				yyerror("internal error");
... ...
@@ -1977,8 +1983,10 @@ switch_cmd:
1977 1977
 	| SWITCH rval_expr LBRACE RBRACE {
1978 1978
 		$$=0;
1979 1979
 		warn("empty switch()");
1980
-		if ($2==0) yyerror("bad expression in switch(...)");
1981
-		else{
1980
+		if ($2==0){
1981
+			yyerror("bad expression in switch(...)");
1982
+			YYERROR;
1983
+		}else{
1982 1984
 			/* it might have sideffects, so leave it for the optimizer */
1983 1985
 			$$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
1984 1986
 			if ($$==0) {
... ...
@@ -1994,12 +2002,13 @@ switch_cmd:
1994 1994
 
1995 1995
 while_cmd:
1996 1996
 	WHILE rval_expr stm {
1997
-		if ($2){
1998
-			if (rve_is_constant($2))
1999
-				warn_at(&$2->fpos, "constant value in while(...)");
2000
-		}else
1997
+		if ($2 && rval_expr_int_check($2)>=0){
1998
+			warn_ct_rve($2, "while");
1999
+			$$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2000
+		}else{
2001 2001
 			yyerror_at(&$2->fpos, "bad while(...) expression");
2002
-		$$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2002
+			YYERROR;
2003
+		}
2003 2004
 	}
2004 2005
 ;
2005 2006