[mono-vb] Patch for ParamArray parsing

Bernie Solomon bernard@ugs.com
Wed, 25 Aug 2004 17:02:03 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_09D2_01C48AC5.3EC53B00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

In looking at overload resolution I found that specifying ByVal and
ParamArray together didn't parse. You see this in various examples. This
fixes that and also changes the error checking for parameter modifiers a
little by allowing more things to parse and detecting problems with some
checks afterwards - this gives better messages on mistakes.

Any problems with this before I commit it?

Bernie Solomon

------=_NextPart_000_09D2_01C48AC5.3EC53B00
Content-Type: text/plain;
	name="mb-parser.jay.diffs.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="mb-parser.jay.diffs.txt"

Index: mb-parser.jay=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/public/mcs/mbas/mb-parser.jay,v=0A=
retrieving revision 1.131=0A=
diff -u -p -r1.131 mb-parser.jay=0A=
--- mb-parser.jay	24 Aug 2004 01:19:58 -0000	1.131=0A=
+++ mb-parser.jay	25 Aug 2004 22:48:33 -0000=0A=
@@ -2216,38 +2216,40 @@ opt_formal_parameter_list=0A=
 	;=0A=
 	=0A=
 formal_parameter_list=0A=
-	: fixed_parameters		=0A=
+	: parameters		=0A=
 	  { =0A=
 		ArrayList pars_list =3D (ArrayList) $1;=0A=
-=0A=
-		Parameter [] pars =3D new Parameter [pars_list.Count];=0A=
-		pars_list.CopyTo (pars);=0A=
-	  	$$ =3D new Parameters (pars, null, lexer.Location); =0A=
+		Parameter [] pars =3D null; =0A=
+		Parameter array_parameter =3D null;=0A=
+		int non_array_count =3D pars_list.Count;=0A=
+		if (pars_list.Count > 0 && (((Parameter) pars_list [pars_list.Count - =
1]).ModFlags & Parameter.Modifier.PARAMS) !=3D 0) {=0A=
+			array_parameter =3D (Parameter) pars_list [pars_list.Count - 1];=0A=
+			non_array_count =3D pars_list.Count - 1;=0A=
+		}=0A=
+		foreach (Parameter par in pars_list)=0A=
+			if (par !=3D array_parameter && (par.ModFlags & =
Parameter.Modifier.PARAMS) !=3D 0) {=0A=
+		  		Report.Error (30192, lexer.Location, "ParamArray parameters must =
be last");=0A=
+			  	non_array_count =3D 0; =0A=
+				array_parameter =3D null;=0A=
+				break;=0A=
+			}=0A=
+		if (non_array_count > 0) {=0A=
+			pars =3D new Parameter [non_array_count];=0A=
+			pars_list.CopyTo (pars);=0A=
+		}=0A=
+	  	$$ =3D new Parameters (pars, array_parameter, lexer.Location); =0A=
 	  } =0A=
-	| fixed_parameters COMMA parameter_array=0A=
-	  {=0A=
-		ArrayList pars_list =3D (ArrayList) $1;=0A=
-=0A=
-		Parameter [] pars =3D new Parameter [pars_list.Count];=0A=
-		pars_list.CopyTo (pars);=0A=
-=0A=
-		$$ =3D new Parameters (pars, (Parameter) $3, lexer.Location); =0A=
-	  }=0A=
-	| parameter_array =0A=
-	  {=0A=
-		$$ =3D new Parameters (null, (Parameter) $1, lexer.Location);=0A=
-	  }=0A=
 	;=0A=
 =0A=
-fixed_parameters=0A=
-	: fixed_parameter	=0A=
+parameters=0A=
+	: parameter	=0A=
 	  {=0A=
 		ArrayList pars =3D new ArrayList ();=0A=
 =0A=
 		pars.Add ($1);=0A=
 		$$ =3D pars;=0A=
 	  }=0A=
-	| fixed_parameters COMMA fixed_parameter=0A=
+	| parameters COMMA parameter=0A=
 	  {=0A=
 		ArrayList pars =3D (ArrayList) $1;=0A=
 =0A=
@@ -2256,7 +2258,7 @@ fixed_parameters=0A=
 	  }=0A=
 	;=0A=
 =0A=
-fixed_parameter=0A=
+parameter=0A=
 	: opt_attributes=0A=
 	  opt_parameter_modifier=0A=
 	  identifier opt_type_character opt_rank_specifiers =
opt_type_with_ranks opt_variable_initializer=0A=
@@ -2266,7 +2268,12 @@ fixed_parameter=0A=
 	  	Expression ptype;=0A=
 	  	=0A=
 	  	if (opt_parm && ($7 =3D=3D null))=0A=
-	  		Report.Error (30812, "Optional parameters must have a default =
value");=0A=
+	  		Report.Error (30812, lexer.Location, "Optional parameters must =
have a default value");=0A=
+=0A=
+	  	if ((pm & Parameter.Modifier.PARAMS) !=3D 0) {=0A=
+		  	if ((pm & ~Parameter.Modifier.PARAMS) !=3D 0)=0A=
+	  			Report.Error (30667, lexer.Location, "ParamArray parameters must =
be ByVal");=0A=
+		}=0A=
 	  	=0A=
 	  	if (opt_parm) {=0A=
 	  		if ((pm & Parameter.Modifier.REF) !=3D0)=0A=
@@ -2280,37 +2287,19 @@ fixed_parameter=0A=
 =0A=
 		ptype =3D (Expression)(($6 =3D=3D null) ? (($4 =3D=3D null) ? =
TypeManager.system_object_expr : $4) : $6);=0A=
 		if ($5 !=3D null)	{=0A=
-	  		string t =3D ptype.ToString();=0A=
+	  		string t =3D ptype.ToString ();=0A=
 	  		if (t.IndexOf('[') >=3D 0)=0A=
 				Report.Error (31087, lexer.Location, "Array types specified in too =
many places");=0A=
 			else	=0A=
 	  			ptype =3D DecomposeQI (t + VariableDeclaration.BuildRanks =
((ArrayList) $5, true, lexer.Location), lexer.Location);=0A=
-	  	}			=0A=
+	  	}=0A=
+		if ((pm & Parameter.Modifier.PARAMS) !=3D 0 && ptype.ToString =
().IndexOf('[') < 0)=0A=
+	  		Report.Error (30050, lexer.Location, "ParamArray parameters must =
be an array type");=0A=
 		$$ =3D new Parameter (ptype, (string) $3, pm,=0A=
 					(Attributes) $1, (Expression) $7, opt_parm);=0A=
 	  }=0A=
 	;=0A=
 	=0A=
-parameter_array=0A=
-	: PARAM_ARRAY identifier opt_parens AS type =0A=
-	  { =0A=
-	  	string s_patype =3D ((Expression) $5).ToString();=0A=
-	  	if ((bool) $3)=0A=
-	  		s_patype +=3D "[]";=0A=
-	  		=0A=
-	  	Expression patype =3D DecomposeQI (s_patype, Location.Null);=0A=
-		$$ =3D new Parameter (patype, (string) $2, Parameter.Modifier.PARAMS, =
null);=0A=
-		// note  ("type must be a single-dimension array type"); =0A=
-	  }=0A=
-	;=0A=
-		=0A=
-opt_parens=0A=
-	: /* empty */=0A=
-	  {	$$ =3D false;	}=0A=
-	| OPEN_PARENS CLOSE_PARENS=0A=
-	  {	$$ =3D true;	}=0A=
-	;=0A=
-	=0A=
 opt_parameter_modifier=0A=
 	: /* empty */		{ $$ =3D Parameter.Modifier.VAL; 	}=0A=
 	| parameter_modifiers	{ $$ =3D $1;			}=0A=
@@ -2325,6 +2314,7 @@ parameter_modifier=0A=
 	: BYREF			{ $$ =3D Parameter.Modifier.REF | =
Parameter.Modifier.ISBYREF; }=0A=
 	| BYVAL			{ $$ =3D Parameter.Modifier.VAL; }=0A=
 	| OPTIONAL		{ $$ =3D Parameter.Modifier.OPTIONAL; } =0A=
+	| PARAM_ARRAY		{ $$ =3D Parameter.Modifier.PARAMS; } =0A=
 	;	=0A=
 =0A=
 opt_statement_list=0A=

------=_NextPart_000_09D2_01C48AC5.3EC53B00--