From: Martin Baulig Date: Thu, 1 Aug 2002 19:07:40 +0000 (-0000) Subject: 2002-08-01 Martin Baulig X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=164b21a8075201c560e40b7deca6ce01f06c4056;p=mono.git 2002-08-01 Martin Baulig * ecore.cs (Expression.report118): Renamed to Error118 and made it public static. * statement.cs (Throw.Resolve): Check whether the expression is of the correct type (CS0118) and whether the type derives from System.Exception (CS0155). (Catch.Resolve): New method. Do the type lookup here and check whether it derives from System.Exception (CS0155). (Catch.CatchType, Catch.IsGeneral): New public properties. * typemanager.cs (TypeManager.exception_type): Added. svn path=/trunk/mcs/; revision=6326 --- diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index e181995ae2a..2b2a9578713 100755 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,3 +1,17 @@ +2002-08-01 Martin Baulig + + * ecore.cs (Expression.report118): Renamed to Error118 and made + it public static. + + * statement.cs (Throw.Resolve): Check whether the expression is of + the correct type (CS0118) and whether the type derives from + System.Exception (CS0155). + (Catch.Resolve): New method. Do the type lookup here and check + whether it derives from System.Exception (CS0155). + (Catch.CatchType, Catch.IsGeneral): New public properties. + + * typemanager.cs (TypeManager.exception_type): Added. + 2002-07-31 Miguel de Icaza * driver.cs: Updated About function. diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index dc607297810..8f6a93a021f 100755 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -3246,7 +3246,7 @@ try_statement ArrayList s = new ArrayList (); foreach (Catch cc in (ArrayList) $3) { - if (cc.Type == null) + if (cc.IsGeneral) g = cc; else s.Add (cc); @@ -3265,7 +3265,7 @@ try_statement if (catch_list != null){ foreach (Catch cc in catch_list) { - if (cc.Type == null) + if (cc.IsGeneral) g = cc; else s.Add (cc); diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index a78d69c24e5..edc9dfd191e 100755 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -2147,7 +2147,7 @@ namespace Mono.CSharp { /// /// Reports that we were expecting `expr' to be of class `expected' /// - protected void report118 (Location loc, Expression expr, string expected) + public static void Error118 (Location loc, Expression expr, string expected) { string kind = "Unknown"; diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index 4558a8411f9..ac1170fdd57 100755 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -776,7 +776,7 @@ namespace Mono.CSharp { return null; } else { - report118 (loc, expr, "variable, indexer or property access"); + Error118 (loc, expr, "variable, indexer or property access"); return null; } @@ -1445,7 +1445,7 @@ namespace Mono.CSharp { } if (target_type.eclass != ExprClass.Type){ - report118 (loc, target_type, "class"); + Error118 (loc, target_type, "class"); return null; } @@ -3826,7 +3826,7 @@ namespace Mono.CSharp { } if (!(expr is MethodGroupExpr)){ - report118 (loc, this.expr, "method group"); + Error118 (loc, this.expr, "method group"); return null; } @@ -4207,7 +4207,7 @@ namespace Mono.CSharp { if (! (ml is MethodGroupExpr)){ if (!is_struct){ - report118 (loc, ml, "method group"); + Error118 (loc, ml, "method group"); return null; } } @@ -4659,7 +4659,7 @@ namespace Mono.CSharp { AllBindingFlags, loc); if (!(ml is MethodGroupExpr)) { - report118 (loc, ml, "method group"); + Error118 (loc, ml, "method group"); return null; } @@ -5755,7 +5755,7 @@ namespace Mono.CSharp { // As long as the type is valid if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess || eclass == ExprClass.Value)) { - report118 (ea.loc, ea.Expr, "variable or value"); + Error118 (ea.loc, ea.Expr, "variable or value"); return null; } #endif @@ -6436,7 +6436,7 @@ namespace Mono.CSharp { return null; if (left.eclass != ExprClass.Type){ - report118 (loc, left, "type"); + Error118 (loc, left, "type"); return null; } diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs index 21cb220d0a3..d1c848b7425 100755 --- a/mcs/mcs/statement.cs +++ b/mcs/mcs/statement.cs @@ -810,6 +810,22 @@ namespace Mono.CSharp { expr = expr.Resolve (ec); if (expr == null) return false; + + ExprClass eclass = expr.eclass; + + if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess || + eclass == ExprClass.Value || eclass == ExprClass.IndexerAccess)) { + Expression.Error118 (loc, expr, "value, variable, property " + + "or indexer access "); + return false; + } + + if (!expr.Type.IsSubclassOf (TypeManager.exception_type)) { + Report.Error (155, loc, + "The type caught or thrown must be derived " + + "from System.Exception"); + return false; + } } ec.CurrentBranching.CurrentUsageVector.Returns = FlowReturns.EXCEPTION; @@ -3635,18 +3651,55 @@ namespace Mono.CSharp { } public class Catch { - public readonly Expression Type; public readonly string Name; public readonly Block Block; public readonly Location Location; + + Expression type; public Catch (Expression type, string name, Block block, Location l) { - Type = type; + this.type = type; Name = name; Block = block; Location = l; } + + public Type CatchType { + get { + if (type == null) + throw new InvalidOperationException (); + + return type.Type; + } + } + + public bool IsGeneral { + get { + return type == null; + } + } + + public bool Resolve (EmitContext ec) + { + if (type != null) { + type = type.DoResolve (ec); + if (type == null) + return false; + + if (!type.Type.IsSubclassOf (TypeManager.exception_type)) { + Report.Error (155, Location, + "The type caught or thrown must be derived " + + "from System.Exception"); + return false; + } + } + + if (!Block.Resolve (ec)) + return false; + + return true; + } } public class Try : Statement { @@ -3697,7 +3750,7 @@ namespace Mono.CSharp { vi.Number = -1; } - if (!c.Block.Resolve (ec)) + if (!c.Resolve (ec)) ok = false; FlowBranching.UsageVector current = ec.CurrentBranching.CurrentUsageVector; @@ -3712,7 +3765,7 @@ namespace Mono.CSharp { ec.CurrentBranching.CreateSibling (); Report.Debug (1, "STARTED SIBLING FOR GENERAL", ec.CurrentBranching); - if (!General.Block.Resolve (ec)) + if (!General.Resolve (ec)) ok = false; FlowBranching.UsageVector current = ec.CurrentBranching.CurrentUsageVector; @@ -3770,13 +3823,9 @@ namespace Mono.CSharp { DeclSpace ds = ec.DeclSpace; foreach (Catch c in Specific){ - Type catch_type = ds.ResolveType (c.Type, false, c.Location); VariableInfo vi; - if (catch_type == null) - return false; - - ig.BeginCatchBlock (catch_type); + ig.BeginCatchBlock (c.CatchType); if (c.Name != null){ vi = c.Block.GetVariableInfo (c.Name); diff --git a/mcs/mcs/typemanager.cs b/mcs/mcs/typemanager.cs index 00f11b31628..d7a03958328 100755 --- a/mcs/mcs/typemanager.cs +++ b/mcs/mcs/typemanager.cs @@ -69,6 +69,7 @@ public class TypeManager { static public Type param_array_type; static public Type void_ptr_type; static public Type indexer_name_type; + static public Type exception_type; static public object obsolete_attribute_type; static public object conditional_attribute_type; @@ -678,6 +679,8 @@ public class TypeManager { indexer_name_type = CoreLookupType ("System.Runtime.CompilerServices.IndexerNameAttribute"); + exception_type = CoreLookupType ("System.Exception"); + // // Attribute types //