update ();
}
+ public void SetThrowsSometimes ()
+ {
+ throws = FlowReturns.Sometimes;
+ update ();
+ }
+
public void SetBarrier ()
{
barrier = FlowReturns.Always;
case BranchingType.Block:
return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc);
+ case BranchingType.Loop:
+ return new FlowBranchingLoop (parent, block, loc);
+
default:
return new FlowBranchingBlock (parent, type, SiblingType.Conditional, block, loc);
}
// </summary>
public readonly Location Location;
+ // <summary>
+ // This is only valid for SwitchSection, Try, Catch and Finally.
+ // </summary>
+ public readonly Block Block;
+
// <summary>
// If this is true, then the usage vector has been modified and must be
// merged when we're done with this branching.
//
// Normally, you should not use any of these constructors.
//
- public UsageVector (SiblingType type, UsageVector parent, Location loc, int num_params, int num_locals)
+ public UsageVector (SiblingType type, UsageVector parent,
+ Block block, Location loc,
+ int num_params, int num_locals)
{
this.Type = type;
+ this.Block = block;
this.Location = loc;
this.InheritsFrom = parent;
this.CountParameters = num_params;
id = ++next_id;
}
- public UsageVector (SiblingType type, UsageVector parent, Location loc)
- : this (type, parent, loc, parent.CountParameters, parent.CountLocals)
+ public UsageVector (SiblingType type, UsageVector parent,
+ Block block, Location loc)
+ : this (type, parent, block, loc,
+ parent.CountParameters, parent.CountLocals)
{ }
public UsageVector (MyBitVector parameters, MyBitVector locals,
- Reachability reachability, Location loc)
+ Reachability reachability, Block block,
+ Location loc)
{
this.Type = SiblingType.Block;
this.Location = loc;
+ this.Block = block;
this.reachability = reachability;
this.parameters = parameters;
// </summary>
public UsageVector Clone ()
{
- UsageVector retval = new UsageVector (Type, null, Location, CountParameters, CountLocals);
+ UsageVector retval = new UsageVector (
+ Type, null, Block, Location,
+ CountParameters, CountLocals);
if (retval.locals != null)
retval.locals = locals.Clone ();
public bool IsAssigned (VariableInfo var)
{
- if (!var.IsParameter && Reachability.AlwaysBreaks)
+ if (!var.IsParameter && Reachability.IsUnreachable)
return true;
return var.IsAssigned (var.IsParameter ? parameters : locals);
public void SetAssigned (VariableInfo var)
{
- if (!var.IsParameter && Reachability.AlwaysBreaks)
+ if (!var.IsParameter && Reachability.IsUnreachable)
return;
IsDirty = true;
public bool IsFieldAssigned (VariableInfo var, string name)
{
- if (!var.IsParameter && Reachability.AlwaysBreaks)
+ if (!var.IsParameter && Reachability.IsUnreachable)
return true;
return var.IsFieldAssigned (var.IsParameter ? parameters : locals, name);
public void SetFieldAssigned (VariableInfo var, string name)
{
- if (!var.IsParameter && Reachability.AlwaysBreaks)
+ if (!var.IsParameter && Reachability.IsUnreachable)
return;
IsDirty = true;
// We're either finite or we may leave the loop.
new_r.SetReturnsSometimes ();
}
+ if (new_r.Throws == FlowReturns.Always) {
+ // We're either finite or we may leave the loop.
+ new_r.SetThrowsSometimes ();
+ }
}
} else if (branching.Type == BranchingType.Switch)
new_r.ResetBreaks ();
// 8 Console.WriteLine (a);
//
// </summary>
- public void MergeJumpOrigins (ICollection origin_vectors)
+ public void MergeJumpOrigins (UsageVector o_vectors)
{
Report.Debug (1, " MERGING JUMP ORIGINS", this);
reachability = Reachability.Never ();
- if (origin_vectors == null)
+ if (o_vectors == null)
return;
bool first = true;
- foreach (UsageVector vector in origin_vectors) {
+ for (UsageVector vector = o_vectors; vector != null;
+ vector = vector.Next) {
Report.Debug (1, " MERGING JUMP ORIGIN", vector);
if (first) {
Report.Debug (1, " MERGING FINALLY ORIGIN DONE", this);
}
+ public void MergeBreakOrigins (UsageVector o_vectors)
+ {
+ Report.Debug (1, " MERGING BREAK ORIGINS", this);
+
+ if (o_vectors == null)
+ return;
+
+ bool first = true;
+
+ for (UsageVector vector = o_vectors; vector != null;
+ vector = vector.Next) {
+ Report.Debug (1, " MERGING BREAK ORIGIN", vector);
+
+ if (first) {
+ if (locals != null && vector.Locals != null)
+ locals.Or (vector.locals);
+
+ if (parameters != null)
+ parameters.Or (vector.parameters);
+ first = false;
+ } else {
+ if (locals != null && vector.Locals != null)
+ locals.And (vector.locals);
+ if (parameters != null)
+ parameters.And (vector.parameters);
+ }
+ }
+
+ Report.Debug (1, " MERGING BREAK ORIGINS DONE", this);
+ }
+
public void CheckOutParameters (FlowBranching branching)
{
if (parameters != null)
local_map = Block.LocalMap;
UsageVector parent_vector = parent != null ? parent.CurrentUsageVector : null;
- vector = new UsageVector (stype, parent_vector, loc, param_map.Length, local_map.Length);
-
-
+ vector = new UsageVector (
+ stype, parent_vector, Block, loc,
+ param_map.Length, local_map.Length);
} else {
param_map = Parent.param_map;
local_map = Parent.local_map;
- vector = new UsageVector (stype, Parent.CurrentUsageVector, loc);
+ vector = new UsageVector (
+ stype, Parent.CurrentUsageVector, null, loc);
}
AddSibling (vector);
// <summary>
// Creates a sibling of the current usage vector.
// </summary>
- public virtual void CreateSibling (SiblingType type)
+ public virtual void CreateSibling (Block block, SiblingType type)
{
- AddSibling (new UsageVector (type, Parent.CurrentUsageVector, Location));
+ UsageVector vector = new UsageVector (
+ type, Parent.CurrentUsageVector, block, Location);
+ AddSibling (vector);
Report.Debug (1, " CREATED SIBLING", CurrentUsageVector);
}
+ public void CreateSibling ()
+ {
+ CreateSibling (null, SiblingType.Conditional);
+ }
+
protected abstract void AddSibling (UsageVector uv);
- public abstract void Label (ArrayList origin_vectors);
+ public virtual LabeledStatement LookupLabel (string name, Location loc)
+ {
+ if (Parent != null)
+ return Parent.LookupLabel (name, loc);
+
+ Report.Error (
+ 159, loc,
+ "No such label `" + name + "' in this scope");
+ return null;
+ }
+
+ public abstract void Label (UsageVector origin_vectors);
// <summary>
// Check whether all `out' parameters have been assigned.
Report.Error (177, loc, "The out parameter `" +
var.Name + "' must be " +
- "assigned before control leave the current method.");
+ "assigned before control leaves the current method.");
}
}
Report.Debug (2, " MERGING SIBLINGS DONE", parameters, locals,
reachability, Infinite);
- return new UsageVector (parameters, locals, reachability, Location);
+ return new UsageVector (
+ parameters, locals, reachability, null, Location);
}
protected abstract UsageVector Merge ();
throw new NotSupportedException ();
UsageVector vector = new UsageVector (
- SiblingType.Conditional, null, Location, param_map.Length, local_map.Length);
+ SiblingType.Conditional, null, Block, Location,
+ param_map.Length, local_map.Length);
UsageVector result = vector.MergeChild (this);
throw new NotSupportedException ();
}
+ public virtual void AddBreakVector (UsageVector vector)
+ {
+ if (Parent != null)
+ Parent.AddBreakVector (vector);
+ else if ((Block == null) || !Block.IsDestructor)
+ throw new NotSupportedException ();
+ }
+
public bool IsAssigned (VariableInfo vi)
{
return CurrentUsageVector.IsAssigned (vi);
sibling_list = sibling;
}
- public override void Label (ArrayList origin_vectors)
+ public override LabeledStatement LookupLabel (string name, Location loc)
+ {
+ if (Block == null)
+ return base.LookupLabel (name, loc);
+
+ LabeledStatement s = Block.LookupLabel (name);
+ if (s != null)
+ return s;
+
+ return base.LookupLabel (name, loc);
+ }
+
+ public override void Label (UsageVector origin_vectors)
{
if (!CurrentUsageVector.Reachability.IsUnreachable) {
- if (origin_vectors == null)
- origin_vectors = new ArrayList (1);
- origin_vectors.Add (CurrentUsageVector.Clone ());
+ UsageVector vector = CurrentUsageVector.Clone ();
+ vector.Next = origin_vectors;
+ origin_vectors = vector;
}
CurrentUsageVector.MergeJumpOrigins (origin_vectors);
}
}
+ public class FlowBranchingLoop : FlowBranchingBlock
+ {
+ UsageVector break_origins;
+
+ public FlowBranchingLoop (FlowBranching parent, Block block, Location loc)
+ : base (parent, BranchingType.Loop, SiblingType.Conditional, block, loc)
+ { }
+
+ public override void AddBreakVector (UsageVector vector)
+ {
+ vector = vector.Clone ();
+ vector.Next = break_origins;
+ break_origins = vector;
+ }
+
+ protected override UsageVector Merge ()
+ {
+ UsageVector vector = base.Merge ();
+
+ vector.MergeBreakOrigins (break_origins);
+
+ return vector;
+ }
+ }
+
public class FlowBranchingException : FlowBranching
{
UsageVector current_vector;
finally_origins = vector;
}
- public override void Label (ArrayList origin_vectors)
+ public override LabeledStatement LookupLabel (string name, Location loc)
+ {
+ if (current_vector.Block == null)
+ return base.LookupLabel (name, loc);
+
+ LabeledStatement s = current_vector.Block.LookupLabel (name);
+ if (s != null)
+ return s;
+
+ if (finally_vector != null) {
+ Report.Error (
+ 157, loc, "Control can not leave the body " +
+ "of the finally block");
+ return null;
+ }
+
+ return base.LookupLabel (name, loc);
+ }
+
+ public override void Label (UsageVector origin_vectors)
{
CurrentUsageVector.MergeJumpOrigins (origin_vectors);
}
Fields = new FieldInfo [Count];
public_fields.CopyTo (Fields, 0);
non_public_fields.CopyTo (Fields, CountPublic);
+ } else if (type is GenericTypeParameterBuilder) {
+ CountPublic = CountNonPublic = Count = 0;
+
+ Fields = new FieldInfo [0];
} else {
FieldInfo[] public_fields = type.GetFields (
BindingFlags.Instance|BindingFlags.Public);