+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.
ArrayList s = new ArrayList ();
foreach (Catch cc in (ArrayList) $3) {
- if (cc.Type == null)
+ if (cc.IsGeneral)
g = cc;
else
s.Add (cc);
if (catch_list != null){
foreach (Catch cc in catch_list) {
- if (cc.Type == null)
+ if (cc.IsGeneral)
g = cc;
else
s.Add (cc);
/// <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";
return null;
} else {
- report118 (loc, expr, "variable, indexer or property access");
+ Error118 (loc, expr, "variable, indexer or property access");
return null;
}
}
if (target_type.eclass != ExprClass.Type){
- report118 (loc, target_type, "class");
+ Error118 (loc, target_type, "class");
return null;
}
}
if (!(expr is MethodGroupExpr)){
- report118 (loc, this.expr, "method group");
+ Error118 (loc, this.expr, "method group");
return null;
}
if (! (ml is MethodGroupExpr)){
if (!is_struct){
- report118 (loc, ml, "method group");
+ Error118 (loc, ml, "method group");
return null;
}
}
AllBindingFlags, loc);
if (!(ml is MethodGroupExpr)) {
- report118 (loc, ml, "method group");
+ Error118 (loc, ml, "method group");
return null;
}
// 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
return null;
if (left.eclass != ExprClass.Type){
- report118 (loc, left, "type");
+ Error118 (loc, left, "type");
return null;
}
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;
}
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 {
vi.Number = -1;
}
- if (!c.Block.Resolve (ec))
+ if (!c.Resolve (ec))
ok = false;
FlowBranching.UsageVector current = ec.CurrentBranching.CurrentUsageVector;
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;
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);
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;
indexer_name_type = CoreLookupType ("System.Runtime.CompilerServices.IndexerNameAttribute");
+ exception_type = CoreLookupType ("System.Exception");
+
//
// Attribute types
//