2002-08-01 Martin Baulig <martin@gnome.org>
authorMartin Baulig <martin@novell.com>
Thu, 1 Aug 2002 19:07:40 +0000 (19:07 -0000)
committerMartin Baulig <martin@novell.com>
Thu, 1 Aug 2002 19:07:40 +0000 (19:07 -0000)
* 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

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/statement.cs
mcs/mcs/typemanager.cs

index e181995ae2a0aba3b480c586cf285ca48434221d..2b2a95787134d5d6f7b2e8ea0ab4bf4bbb753988 100755 (executable)
@@ -1,3 +1,17 @@
+2002-08-01  Martin Baulig  <martin@gnome.org>
+
+       * 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  <miguel@ximian.com>
 
        * driver.cs: Updated About function.
index dc60729781066396c480390b99fdebaa9e8d6245..8f6a93a021fb254ab054ebf0fa6634765750f8d0 100755 (executable)
@@ -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);
index a78d69c24e5a224df99ad795a53f61d5e4f1aebd..edc9dfd191ed6c5502d75cfc55578197f5d4ecda 100755 (executable)
@@ -2147,7 +2147,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Reports that we were expecting `expr' to be of class `expected'
                /// </summary>
-               protected void report118 (Location loc, Expression expr, string expected)
+               public static void Error118 (Location loc, Expression expr, string expected)
                {
                        string kind = "Unknown";
                        
index 4558a8411f91160e96a8543383e2d5603bc327c5..ac1170fdd57f57977457b434ae457b31c1d771ae 100755 (executable)
@@ -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;
                        }
                        
index 21cb220d0a3a30042ccf873d7f2526a7a8229bf0..d1c848b742501e6f59fd8a5e93685ba08841a2d9 100755 (executable)
@@ -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);
index 00f11b31628cd645170e2821ad524f2474e97df4..d7a03958328367d68e668a5147b4bd885fbc91b7 100755 (executable)
@@ -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
                //