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 1983
 	| SWITCH rval_expr LBRACE RBRACE {
1978 1984
 		$$=0;
1979 1985
 		warn("empty switch()");
1980
-		if ($2==0) yyerror("bad expression in switch(...)");
1981
-		else{
1986
+		if ($2==0){
1987
+			yyerror("bad expression in switch(...)");
1988
+			YYERROR;
1989
+		}else{
1982 1990
 			/* it might have sideffects, so leave it for the optimizer */
1983 1991
 			$$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
1984 1992
 			if ($$==0) {
... ...
@@ -1994,12 +2002,13 @@ switch_cmd:
1994 2002
 
1995 2003
 while_cmd:
1996 2004
 	WHILE rval_expr stm {
1997
-		if ($2){
1998
-			if (rve_is_constant($2))
1999
-				warn_at(&$2->fpos, "constant value in while(...)");
2000
-		}else
2005
+		if ($2 && rval_expr_int_check($2)>=0){
2006
+			warn_ct_rve($2, "while");
2007
+			$$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2008
+		}else{
2001 2009
 			yyerror_at(&$2->fpos, "bad while(...) expression");
2002
-		$$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2010
+			YYERROR;
2011
+		}
2003 2012
 	}
2004 2013
 ;
2005 2014