// Author:
// Miguel de Icaza (miguel@ximian.com)
// Martin Baulig (martin@gnome.org)
+// Anirban Bhattacharjee (banirban@novell.com)
//
// (C) 2001, 2002 Ximian, Inc.
//
if ((t != TypeManager.exception_type) &&
!t.IsSubclassOf (TypeManager.exception_type) &&
!(expr is NullLiteral)) {
- Report.Error (155, loc,
+ Report.Error (30665, loc,
"The type caught or thrown must be derived " +
"from System.Exception");
return false;
{
ILGenerator ig = ec.ig;
- if (type != ExitType.SUB && type != ExitType.FUNCTION && type != ExitType.PROPERTY) {
+ if (type != ExitType.SUB && type != ExitType.FUNCTION &&
+ type != ExitType.PROPERTY && type != ExitType.TRY) {
if (ec.InLoop == false && ec.Switch == null){
- Report.Error (139, loc, "No enclosing loop or switch to exit from");
+ if (type == ExitType.FOR)
+ Report.Error (30096, loc, "No enclosing FOR loop to exit from");
+ if (type == ExitType.WHILE) \r
+ Report.Error (30097, loc, "No enclosing WHILE loop to exit from");
+ if (type == ExitType.DO)
+ Report.Error (30089, loc, "No enclosing DO loop to exit from");
+ if (type == ExitType.SELECT)
+ Report.Error (30099, loc, "No enclosing SELECT to exit from");
+
return false;
}
ig.Emit (OpCodes.Br, ec.LoopEnd);
} else {
if (ec.InFinally){
- Report.Error (157,loc,"Control can not leave the body of the finally block");
+ Report.Error (30393, loc,
+ "Control can not leave the body of the finally block");
return false;
}
public class Catch {
public readonly string Name;
public readonly Block Block;
+ public Expression Clause;
public readonly Location Location;
Expression type_expr;
+ //Expression clus_expr;
Type type;
- public Catch (Expression type, string name, Block block, Location l)
+ public Catch (Expression type, string name, Block block, Expression clause, Location l)
{
type_expr = type;
Name = name;
Block = block;
+ Clause = clause;
Location = l;
}
return false;
if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
- Report.Error (155, Location,
+ Report.Error (30665, Location,
"The type caught or thrown must be derived " +
"from System.Exception");
return false;
} else
type = null;
+ if (Clause != null) {
+ Clause = Statement.ResolveBoolean (ec, Clause, Location);
+ if (Clause == null) {
+ return false;
+ }
+ }
+
if (!Block.Resolve (ec))
return false;
ig.Emit (OpCodes.Stloc, vi.LocalBuilder);
} else
ig.Emit (OpCodes.Pop);
-
- if (!c.Block.Emit (ec))
- returns = false;
+
+ //
+ // if when clause is there
+ //
+ if (c.Clause != null) {
+ if (c.Clause is BoolConstant) {
+ bool take = ((BoolConstant) c.Clause).Value;
+
+ if (take)
+ if (!c.Block.Emit (ec))
+ returns = false;
+ } else {
+ EmitBoolExpression (ec, c.Clause, finish, false);
+ if (!c.Block.Emit (ec))
+ returns = false;
+ }
+ } else
+ if (!c.Block.Emit (ec))
+ returns = false;
}
if (General != null){
ig.BeginCatchBlock (TypeManager.object_type);
ig.Emit (OpCodes.Pop);
- if (!General.Block.Emit (ec))
- returns = false;
+
+ if (General.Clause != null) {
+ if (General.Clause is BoolConstant) {
+ bool take = ((BoolConstant) General.Clause).Value;
+ if (take)
+ if (!General.Block.Emit (ec))
+ returns = false;
+ } else {
+ EmitBoolExpression (ec, General.Clause, finish, false);
+ if (!General.Block.Emit (ec))
+ returns = false;
+ }
+ } else
+ if (!General.Block.Emit (ec))
+ returns = false;
}
+
ec.InCatch = old_in_catch;
ig.MarkLabel (finish);
public class AddHandler : Statement {
Expression EvtId;
Expression EvtHandler;
- Expression EvtTarget;
- public AddHandler (Expression evt_id, Expression evt_handler,
- Expression evt_target, Location l)
+ //
+ // keeps track whether EvtId is already resolved
+ //
+ bool resolved;
+
+ public AddHandler (Expression evt_id, Expression evt_handler, Location l)
{
EvtId = evt_id;
EvtHandler = evt_handler;
- EvtTarget = evt_target;
loc = l;
+ resolved = false;
//Console.WriteLine ("Adding handler '" + evt_handler + "' for Event '" + evt_id +"'");
}
public override bool Resolve (EmitContext ec)
{
+ //
+ // if EvetId is of EventExpr type that means
+ // this is already resolved
+ //
+ if (EvtId is EventExpr) {
+ resolved = true;
+ return true;
+ }
+
EvtId = EvtId.Resolve(ec);
EvtHandler = EvtHandler.Resolve(ec,ResolveFlags.MethodGroup);
- EvtTarget = EvtTarget.Resolve (ec,ResolveFlags.VariableOrValue);
if (EvtId == null || (!(EvtId is EventExpr))) {
Report.Error (30676, "Need an event designator.");
return false;
Report.Error (999, "'AddHandler' statement needs an event handler.");
return false;
}
- //EventExpr ee = (EventExpr) EvtId;
- //MethodGroupExpr me = (MethodGroupExpr) EvtHandler;
- //bool b = EvtId.Type.IsSubclassOf (TypeManager.delegate_type);
- //ee.EventInfo.AddEventHandler(EvtTarget, new System.Delegate())
+
return true;
}
protected override bool DoEmit (EmitContext ec)
{
+ //
+ // Already resolved and emitted don't do anything
+ //
+ if (resolved)
+ return true;
+
Expression e, d;
ArrayList args = new ArrayList();
Argument arg = new Argument (EvtHandler, Argument.AType.Expression);
args.Add (arg);
+
+
// The even type was already resolved to a delegate, so
// we must un-resolve its name to generate a type expression
string ts = (EvtId.Type.ToString()).Replace ('+','.');
{
Expression EvtId;
Expression EvtHandler;
- Expression EvtTarget;
- public RemoveHandler (Expression evt_id, Expression evt_handler,
- Expression evt_target, Location l)
+ public RemoveHandler (Expression evt_id, Expression evt_handler, Location l)
{
EvtId = evt_id;
EvtHandler = evt_handler;
- EvtTarget = evt_target;
loc = l;
}
{
EvtId = EvtId.Resolve(ec);
EvtHandler = EvtHandler.Resolve(ec,ResolveFlags.MethodGroup);
- EvtTarget = EvtTarget.Resolve (ec,ResolveFlags.VariableOrValue);
if (EvtId == null || (!(EvtId is EventExpr))) \r
{
Report.Error (30676, "Need an event designator.");
// TODO: we are in a foreach we probably can't reuse ReDimExpr, must turn it into an array(list)
if (Preserve)
{
- // TODO: Generate call to copying code, which has to make lots of verifications
- //PreserveExpr = (ExpressionStatement) new Preserve(RedimTarget, acExpr, loc);
- //ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, PreserveExpr, loc), loc);
- ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, acExpr, loc), loc);
+ ExpressionStatement PreserveExpr = (ExpressionStatement) new Preserve(RedimTarget, acExpr, loc);
+ ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, PreserveExpr, loc), loc);
}
else
ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, acExpr, loc), loc);